Published on :
Administration INTERNAL_CREATION

CAS Session and Connect Management and Data Creation

This code is also available in: Deutsch Français
Awaiting validation
Attention : This code requires administrator privileges.
The script begins by setting network encryption options. It then displays various information about the client environment via `%put` macros and system variables (`&sysuserid`, `&syshostname`, etc.). It configures parameters for a CAS session, including the session name, type, namespace, and CAS server, then establishes a connection to the latter. A section is dedicated to configuring a SAS©/CONNECT session, with the option to choose between an internal ClusterIP or an external NodePort. The script then uses `SIGNON` to connect to the remote server with specific credentials. After establishing the sessions, it executes `rsubmit` commands to display the server environment's system variables and create a large dataset (`remote studio`) on the remote server. A similar dataset (`local studio`) is created locally. Session management includes comments for CAS session termination and disconnection from all SAS©/CONNECT sessions.
Data Analysis

Type : INTERNAL_CREATION


Data is generated internally by the script via DATA STEPs, using the `ranuni` function to create random values. No external files are read.

1 Code Block
Global Options and %put macros
Explanation :
This block configures the network encryption algorithm to SSL. It then displays information about the local SAS client environment using `%put` macros and various system variables and macro functions (`&sysuserid`, `&syshostname`, `%sysget`). This allows verification of the current SAS session's configuration and identity.
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 Session Management
Explanation :
This block initializes macro variables (`_sessionName`, `_sessionType`, `_namespace`, `_casserver`) used to specify the details for connecting to a CAS server. The `cas` command is then used to establish a named CAS session, specifying the CAS controller host, port, and session options, such as metrics collection. This prepares the environment for CAS code execution.
Copied!
1/* CAS session */
2%let _sessionName=&sysuserid;
3%let _sessionType=studio;
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);
3 Code Block
SAS/CONNECT Session Management
Explanation :
This block prepares and establishes a SAS/CONNECT connection. It defines the `host` macro variable with the address and port of the remote connect server. The `SIGNON` command is then used to connect to the remote server using credentials (`geladm`, `lnxsas`). `%syslput` is used to send the value of `_sessionType` to the remote environment, making it available for subsequent `rsubmit` blocks.
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 %put (Remote)
Explanation :
This block, executed on the remote server via `rsubmit`, displays detailed information about the SAS server environment. It uses the same system variables and macro functions as the client block to provide an overview of the remote server's user, process, and environment.
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 creates a local SAS dataset named `localstudio` (using the value of `_sessionType`). It generates 100 million observations, each with two variables: `i` (a counter) and `j` (a random numeric value generated by the `ranuni` function). This block illustrates the creation of large in-memory data on the local session.
Copied!
1DATA local&_sessionType;
2 DO i=1 to 100000000;
3 j=ranuni(1234);
4 OUTPUT;
5 END;
6RUN;
6 Code Block
DATA STEP (Remote) and %sysrput Macro Data
Explanation :
Executed on the remote server via `rsubmit`, this block first displays the value of the `_sessionTypeRemote` macro. It then creates a large remote SAS dataset named `remotestudio` (using the value of `_sessionTypeRemote`) with 100 million observations and random values similar to the local block. Finally, `%sysrput` is used to retrieve the path of the remote server's work directory (`work`) and store it in the `rsaswork` macro of the local session, allowing this path to be referenced after `endrsubmit`.
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 displays the value of the `rsaswork` macro (the remote work directory path) and then assigns a SAS library (`libname`) named `rsaswork`. This library is linked to the remote path (`&rsaswork`) and uses the SAS/CONNECT session (`server=host`) to access the data residing there. This allows interaction with remote server data from the local session.
Copied!
1%put "&rsaswork";
2LIBNAME rsaswork "&rsaswork" server=host;
3 
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 with SAS Viya, mastering the interplay between the Client, Remote Compute, and CAS (Cloud Analytic Services) is the key to scalable performance. This script effectively demonstrates a hybrid architecture where tasks are distributed based on their specific strengths: local coordination, remote task offloading via RSUBMIT, and massively parallel processing potential in CAS »