Published on :

Parallel Execution of CAS Regressions with SAS/CONNECT

This code is also available in: Deutsch Español Français
Awaiting validation
Attention : This code requires administrator privileges.
The script begins by initializing two SAS©/CONNECT sessions ('session1' and 'session2'), configuring each to launch a remote SAS© process. For each session, the code asynchronously (non-blocking) submits a series of operations: defining CAS options, connecting to a specific CAS controller, loading the 'cars' table from the SASHELP library to a CAS table in 'casuser', and executing a 'simple.regression' action with different parameters for each session (alpha, order). The results of each regression are then saved in temporary CAS tables, and specific metadata is retrieved via the 'table.fetch' action. Once submissions are complete, the main script waits for the completion of both remote sessions, retrieves their respective logs and results, then proceeds to disconnect and close the SAS©/CONNECT sessions.
Data Analysis

Type : SASHELP


The data used for regressions is based on the 'cars' table from the internal SASHELP library. This table is loaded into each remote session to a CAS table ('casuser.cars') before being used by the CAS regression actions.

1 Code Block
SAS/CONNECT
Explanation :
This block establishes two distinct SAS/CONNECT sessions, 'session1' and 'session2'. Each 'signon' initiates a remote SAS process, allowing code execution in parallel or in a distributed manner. The 'sascmd' option specifies the command to execute to start the remote SAS process.
Copied!
1signon session1 sascmd="!sascmd -nosyntaxcheck -noterminal";
2signon session2 sascmd="!sascmd -nosyntaxcheck -noterminal";
3 
2 Code Block
DATA STEP Data
Explanation :
This block asynchronously submits code to 'session1' (WAIT=NO). It configures CAS options for the remote session, establishes a connection to the specified CAS controller with an extended timeout, makes all caslibs available, and then uses a DATA STEP to load the 'cars' table from SASHELP into a new CAS table named 'cars' within the 'casuser' caslib. This table will be the source for CAS analyses.
Copied!
1rsubmit session1 wait=no;
2options casdatalimit=10G;
3options compress=yes;
4 
5cas host="19w47mpp-2.gtp-americas.sashq-d.openstack.sas.com"
6 port=5570
7 sessopts=(TIMEOUT=99,DQLOCALE=ENUSA);
8 
9caslib _all_ assign;
10 
11DATA casuser.cars;
12 SET sashelp.cars;
13RUN;
3 Code Block
PROC CAS Data
Explanation :
In 'session1', this block executes a 'simple.regression' action via PROC CAS. It specifies 'mpg_highway' as the target variable and 'weight' as the input variable, with an alpha significance level of 0.05 and a polynomial order of 3. The regression results are saved in a CAS table 'reg1', and specific variables from these results are retrieved for later analysis via the 'table.fetch' action.
Copied!
1PROC CAS;
2SESSION casauto;
3SIMPLE.regression RESULT=reg STATUS=rc /
4 alpha=0.05,
5 order=3,
6 target="mpg_highway",
7 inputs={"weight"},
8 TABLE={caslib="casuser", name="cars"};
9RUN;
10 IF (rc.severity == 0) THEN DO;
11 saveresult reg casout="reg1";
12 
13 TABLE.fetch /
14 fetchvars={
15 {name="response", label="Response"},
16 {name="regressor", label="Regressor"},
17 "intercept", "linear", "quadratic",
18 "ymean", "Ystd", "xmean" , "Xstd"},
19 TABLE="reg1",
20 index=false;
21 END;
22RUN;
23QUIT;
24endrsubmit;
4 Code Block
DATA STEP Data
Explanation :
This block, asynchronously submitted to 'session2', is similar to the corresponding block in 'session1'. It configures CAS options, connects to the same CAS controller, makes caslibs available, and loads the 'cars' table from SASHELP to a CAS table 'casuser.cars'. This allows 'session2' to operate independently and in parallel for its own CAS analyses.
Copied!
1rsubmit session2 wait=no;
2options casdatalimit=10G;
3options compress=yes;
4 
5cas host="19w47mpp-2.gtp-americas.sashq-d.openstack.sas.com"
6 port=5570
7 sessopts=(TIMEOUT=99,DQLOCALE=ENUSA);
8 
9caslib _all_ assign;
10 
11DATA casuser.cars;
12 SET sashelp.cars;
13RUN;
5 Code Block
PROC CAS Data
Explanation :
In 'session2', this block also executes a 'simple.regression' action via PROC CAS on 'casuser.cars', but with different parameters: an alpha level of 0.15 and a polynomial order of 2. The results are saved in a CAS table 'reg2', and the same key variables are retrieved as in 'session1' to allow comparison or analysis of the different regression models.
Copied!
1PROC CAS;
2SESSION casauto;
3SIMPLE.regression RESULT=reg2 STATUS=rc /
4 alpha=0.15,
5 order=2,
6 target="mpg_highway",
7 inputs={"weight"},
8 TABLE={caslib="casuser", name="cars"};
9RUN;
10 IF (rc.severity == 0) THEN DO;
11 saveresult reg2 casout="reg2";
12 
13 TABLE.fetch /
14 fetchvars={
15 {name="response", label="Response"},
16 {name="regressor", label="Regressor"},
17 "intercept", "linear", "quadratic",
18 "ymean", "Ystd", "xmean" , "Xstd"},
19 TABLE="reg2",
20 index=false;
21 END;
22 
23RUN;
24QUIT;
25 
26endrsubmit;
6 Code Block
SAS/CONNECT
Explanation :
This final block manages the synchronization and closing of SAS/CONNECT sessions. The 'waitfor _all_ session1 session2;' statement blocks the main program's execution until both remote sessions have completed their tasks. 'rget' is then used to retrieve the logs and results (if any) from each session. Finally, 'signoff' disconnects and properly terminates the SAS/CONNECT sessions.
Copied!
1waitfor _all_ session1 session2;
2 
3rget session1;
4 
5rget session2;
6 
7signoff session1;
8signoff session2;
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.
Copyright Info : Copyright © 2021, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. SPDX-License-Identifier: Apache-2.0