Published on :

Configuring and Connecting to a Remote SAS Session

This code is also available in: Deutsch Español Français
Awaiting validation
Attention : This code requires administrator privileges.
The script begins by setting a network encryption option for SSL. It then uses several `%put` macros with system macros (`&sysuserid`, `&syshostname`, etc.) to display information about the execution environment of the local SAS© session (client). Variables for a CAS session are defined for future configuration purposes, although the CAS connection itself is commented out and not active in this execution. The script then proceeds to establish a SAS©/CONNECT connection to a specified remote host, using an explicit username and password. Once connected, an `rsubmit` block is executed on the remote server, displaying remote system information and creating a large temporary data table. A similar data table is also created locally. Finally, the script retrieves the path of the remote working directory (`WORK`) and uses it to define a `rsaswork` libname in the local session, allowing direct access to files created in the remote workspace.
Data Analysis

Type : MIXTE


Data is created directly within the script via `DATA` steps that generate 100 million random observations into temporary tables, both locally and on the remote session. System information is also used and displayed via access to SAS system macros (`%sysget`, `&sysuserid`, etc.).

1 Code Block
Macros système
Explanation :
This block initializes the SSL network encryption option. It then uses `%put` macros to display various environment and process information of the local SAS session (client), such as user ID, host name, process ID, process mode, and the state of SAS Viya-specific environment variables (`SASCLOUDNATIVE`, `TCPNOIPADDR`, `SAS_SERVICES_URL`).
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
Macros
Explanation :
This block defines macro variables (`_sessionName`, `_sessionType`, `_namespace`, `_casserver`) intended for use in connecting to a CAS session. The actual CAS connection line (`cas ...`) is commented out, indicating that the connection is not actively established in this script execution.
Copied!
1/* CAS session */
2%let _sessionName=&sysuserid;
3%let _sessionType=sas9;
4%let _namespace=gelcorp;
5%let _casserver=default;
6 
7/* Start a CAS session on the cas-shared-&_casserver CAS server */
8* cas &_sessionName._&_sessionType host="controller.sas-cas-server-&_casserver..&_namespace..svc.cluster.local" port=5570 sessopts=(metrics=true);
3 Code Block
SAS/CONNECT
Explanation :
This block configures connection parameters for a SAS/CONNECT session. It defines the `host` macro with the remote server's address (an external NodePort is chosen). The `SIGNON` statement establishes the connection to the remote server using the username 'geladm' and an explicit password. The `%syslput` macro is used to send the value of `_sessionType` to the remote session, where it will be accessible via `_sessionTypeRemote`.
Copied!
1/* Connect session */
2/* INTERNAL ClusterIP */
3* %let host=sas-connect-spawner 17551;
4/* EXTERNAL NodePort */
5%let host=gelcorp.pdcesx03138.race.sas.com 30377;
6 
7SIGNON host user='geladm' pass='lnxsas';
8%syslput _sessionTypeRemote=&_sessionType;
4 Code Block
Macros système
Explanation :
This `rsubmit` block executes code on the remote SAS session. It uses `%put` macros similar to those on the client to display environment and process information of the remote server. This is useful for verifying the configuration and identity of the remote session.
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;
5 Code Block
DATA STEP Data
Explanation :
This `DATA STEP` block is executed locally and creates a large SAS table named `local` followed by the value of `_sessionType` (e.g., `localsas9`). The table contains two variables (`i` and `j`) and is populated with 100 million observations, with `j` being a random number.
Copied!
1DATA local&_sessionType;
2 DO i=1 to 100000000;
3 j=ranuni(1234);
4 OUTPUT;
5 END;
6RUN;
6 Code Block
DATA STEP Data
Explanation :
This `rsubmit` block executes code on the remote SAS session. It creates a SAS table similar to the previous block, but this time on the remote server, named `remote` followed by the value of `_sessionTypeRemote`. After data creation, the `%sysrput` macro is used to transfer the path of the remote working directory (`WORK`) to a macro variable named `rsaswork` in the local session.
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;
7 Code Block
LIBNAME
Explanation :
This block first displays the value of the macro variable `rsaswork` (which contains the path to the remote working directory). Then, the `LIBNAME` statement is used to define a library named `rsaswork` in the local session, pointing to the remote session's working directory via the established SAS/CONNECT connection. This allows the local session to access files created in the remote workspace.
Copied!
1%put "&rsaswork";
2LIBNAME rsaswork "&rsaswork" server=host;
3 
8 Code Block
Commentaires
Explanation :
This block contains commented-out code sections. The first section would have kept the remote session open for a given period (`call sleep`). The second section contains the `signoff _all;` command and `cas ... terminate;` which would have been used to terminate SAS/CONNECT and CAS sessions if they had been established. These lines are included as an example or reference but are not active in the current script execution.
Copied!
1/* When running as a batch job - need to keep the session open fro fe minutes */
2/*
3rsubmit;
4 data _null_;
5 call sleep(5,60);
6 run;
7endrsubmit;
8*/
9 
10* waitfor _all_;
11 
12 
13/* Close both CAS and connect sessions */
14/*
15cas &_sessionName._&_sessionType terminate;
16signoff _all_;
17*/
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.