Published on :
Administration CREATION_INTERNE

SAS/CONNECT and CAS Session Management

This code is also available in: Deutsch Español Français
Awaiting validation
Attention : This code requires administrator privileges.
The script begins by displaying information about the client execution environment (user ID, host, process). It then attempts to retrieve system variable states related to SASCLOUDNATIVE and TCPNOIPADDR, as well as the SAS© services URL. It initializes and starts a CAS session, then establishes a SAS©/CONNECT connection to a remote host (internal or external depending on configuration). After displaying similar information for the remote environment via RSUBMIT, it creates a large table locally, then another large table on the remote server. It uses the LIBNAME statement to access the remote working directory from the local session. A 5-minute pause is included in the remote session to keep the session open if executed in batch mode. Finally, it cleanly terminates the CAS and SAS©/CONNECT sessions.
Data Analysis

Type : CREATION_INTERNE


Data is internally generated within the script using DATA STEPs that create two distinct tables (one local and one remote), each with 100 million observations and a random numeric variable.

1 Code Block
MACRO
Explanation :
This block initializes the `NETENCRYPTALGORITHM` option to `SSL` for network security. It then displays various information about the local client execution environment, such as user ID, host name, process name and ID, and its mode. It also retrieves and displays the state of the `SASCLOUDNATIVE`, `TCPNOIPADDR`, and `SAS_SERVICES_URL` environment variables.
Copied!
1OPTIONS NETENCRYPTALGORITHM=SSL;
2 
3%put ********** CLIENT ********;
4%put My local user ID is: &sysuserid;
5%put The local host name is: &syshostname;
6%put The local process name is: &sysprocessname;
7%put The local process ID is: &sysprocessid;
8%put The local process mode is: &sysprocessmode;
9 
10%let SASCLOUDNATIVE_state="%sysget(SASCLOUDNATIVE)";
11%put &SASCLOUDNATIVE_state;
12 
13%let TCPNOIPADDR_state="%sysget(TCPNOIPADDR)";
14%put &TCPNOIPADDR_state;
15 
16%let ENVIRONMENT="%sysget(SAS_SERVICES_URL)";
17%put &ENVIRONMENT;
2 Code Block
CAS / SAS/CONNECT
Explanation :
This block defines macro variables to configure a CAS session, including the session name, type, namespace, and CAS server. It then starts a CAS session with the specified parameters. Next, it defines the host for a SAS/CONNECT connection (with options for an internal ClusterIP or an external NodePort) and establishes a SAS/CONNECT session to the remote server using a defined user and password. Finally, it passes the `_sessionType` macro variable to the remote session via `%syslput`.
Copied!
1/* CAS session */
2%let _sessionName=&sysuserid;
3%let _sessionType=batch;
4%let _namespace=gelcorp;
5%let _casserver=default;
6 
7/* Start a CAS session on the cas-shared-&_casserver CAS server */
8cas &_sessionName._&_sessionType host="controller.sas-cas-server-&_casserver..&_namespace..svc.cluster.local" port=5570 sessopts=(metrics=true);
9 
10 
11/* Connect session */
12/* INTERNAL ClusterIP */
13 %let host=sas-connect-spawner 17551;
14/* EXTERNAL NodePort */
15* %let host=gelcorp.pdcesx03138.race.sas.com 30377;
16 
17SIGNON host user='geladm' pass='lnxsas';
18%syslput _sessionTypeRemote=&_sessionType;
3 Code Block
MACRO (via RSUBMIT)
Explanation :
This block is executed on the remote server via `RSUBMIT`. It displays information similar to the client but for the remote server environment, such as user ID, host, process name and ID, and its mode. It also retrieves and displays the state of the `SASCLOUDNATIVE`, `TCPNOIPADDR`, and `SAS_SERVICES_URL` environment variables on the server.
Copied!
1rsubmit;
2 %put ********** SERVER ********;
3 %put My remote user ID is: &sysuserid;
4 %put The remote host name is: &syshostname;
5 %put The remote process name is: &sysprocessname;
6 %put The remote process ID is: &sysprocessid;
7 %put The remote process mode is: &sysprocessmode;
8 
9 %let SASCLOUDNATIVE_state="%sysget(SASCLOUDNATIVE)";
10 %put &SASCLOUDNATIVE_state;
11
12 %let TCPNOIPADDR_state="%sysget(TCPNOIPADDR)";
13 %put &TCPNOIPADDR_state;
14
15 %let ENVIRONMENT="%sysget(SAS_SERVICES_URL)";
16 %put &ENVIRONMENT;
17endrsubmit;
4 Code Block
DATA STEP Data
Explanation :
This DATA STEP block creates a SAS table named `localbatch` (where `&_sessionType` is 'batch') in the local work library. This table is generated with 100 million observations, each containing an index `i` and a variable `j` filled with random numbers.
Copied!
1DATA local&_sessionType;
2 DO i=1 to 100000000;
3 j=ranuni(1234);
4 OUTPUT;
5 END;
6RUN;
5 Code Block
DATA STEP / MACRO (via RSUBMIT) Data
Explanation :
This block, executed via `RSUBMIT` on the remote server, first displays the remote session type. It then creates a SAS table named `remotebatch` in the remote server's work library, similar to the local table, with 100 million random observations. Finally, it uses `%sysrput` to return the path to the remote server's work library to the local session, stored in the `rsaswork` macro variable.
Copied!
1rsubmit;
2 %put &_sessionTypeRemote;
3 
4 DATA remote&_sessionTypeRemote;
5 DO i=1 to 100000000;
6 j=ranuni(1234);
7 OUTPUT;
8 END;
9 RUN;
10 
11 %sysrput rsaswork=%sysfunc(pathname(work));
12endrsubmit;
6 Code Block
LIBNAME
Explanation :
This block displays the path of the remote work library. It then uses a `LIBNAME` statement to create a `rsaswork` shortcut in the local SAS session, which points to the path of the remote work library (`&rsaswork`) using the SAS/CONNECT connection (`server=host`). This allows the local session to directly access data stored in the remote server's working directory.
Copied!
1%put "&rsaswork";
2LIBNAME rsaswork "&rsaswork" server=host;
3 
7 Code Block
DATA STEP (via RSUBMIT)
Explanation :
Executed on the remote server via `RSUBMIT`, this `DATA _NULL_` block uses the `CALL SLEEP` function to pause the remote session for 5 minutes (300 seconds). This is useful for keeping the session active, especially in batch processing environments where the session might otherwise terminate prematurely.
Copied!
1rsubmit;
2 DATA _null_;
3 call sleep(5,60);
4 RUN;
5endrsubmit;
8 Code Block
CAS / SAS/CONNECT
Explanation :
This block ensures the clean closure of open sessions. It terminates the CAS session specified by `&_sessionName._&_sessionType` and uses `SIGNOFF _ALL_` to disconnect all active SAS/CONNECT sessions.
Copied!
1* waitfor _all_;
2 
3 
4/* Close both CAS and connect sessions */
5cas &_sessionName._&_sessionType terminate;
6signoff _all_;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Banner
Expert Advice
Expert
Michael
Responsable de l'infrastructure Viya.
« When working in a cloud-native environment like SAS Viya, the ability to bridge Client, Remote SAS 9.4/Viya Compute, and CAS (Cloud Analytic Services) is essential for high-performance data processing. This script demonstrates a "distributed triangulation" approach: running local logic, offloading heavy compute to a remote spawner via RSUBMIT, and leveraging CAS for in-memory analytics. »