BookmarkSubscribeRSS Feed
idziemianczyk
Obsidian | Level 7

The contex: I would like to know, what is the current active(default) session.

 

Please, check the piece of code and explain how steps 7-9 work. 

 

/*1. Create 3 cas sessions  */
cas s1;
cas s2;
cas s3;

/*2. List the sessions - we can see 3 sessions. Looks OK  */
cas _ALL_ list ;

/*3. Use _CASNAME_ to check the active session. Looks OK */
%put We expect S3 &=_CASNAME_;

/*4. Assign caslib. Created for S3. Looks OK  */
libname casuser cas caslib=casuser;

/*5. Terminate session S3  */
cas s3 terminate;

/*6. List the sessions - we can see 2 sessions. Looks OK  */
cas _ALL_ list ;

/*7. CASNAME is still S3, but I expect to see S2.  */
%put We expect S2 &=_CASNAME_;

/*8. Libname creates new cas session S3. I expect to see connection S2  */
libname casuser cas caslib=casuser;

/*9. After the libname we again see 3 cas session. S3 was automatically created  */
cas _ALL_ list ;

The log I have:

 
82   /*1. Create 3 cas sessions  */
83   cas s1;
NOTE: The session S1 connected successfully to Cloud Analytic Services dvmictsas001.health.fgov.be using port 5570. The UUID is 
      204a4f74-9c47-6541-a0e8-9c6ff6fb8f45. The user is dki and the active caslib is CASUSER(dki).
NOTE: The SAS option SESSREF was updated with the value S1.
NOTE: The SAS macro _SESSREF_ was updated with the value S1.
NOTE: The session is using 0 workers.
84   cas s2;
NOTE: The session S2 connected successfully to Cloud Analytic Services dvmictsas001.health.fgov.be using port 5570. The UUID is 
      13db7c51-6693-7c4b-8746-a9b2b45047f5. The user is dki and the active caslib is CASUSER(dki).
NOTE: The SAS option SESSREF was updated with the value S2.
NOTE: The SAS macro _SESSREF_ was updated with the value S2.
NOTE: The session is using 0 workers.
85   cas s3;
NOTE: The session S3 connected successfully to Cloud Analytic Services dvmictsas001.health.fgov.be using port 5570. The UUID is 
      8bba1ab2-6287-ee41-a8e0-05fdb1419acb. The user is dki and the active caslib is CASUSER(dki).
NOTE: The SAS option SESSREF was updated with the value S3.
NOTE: The SAS macro _SESSREF_ was updated with the value S3.
NOTE: The session is using 0 workers.
86   
87   /*2. List the sessions - we can see 3 sessions. Looks OK  */
88   cas _ALL_ list ;
NOTE: Session S1 is ACTIVE using port 5570 and host dvmictsas001.health.fgov.be for user dki. The session UUID is 
      204a4f74-9c47-6541-a0e8-9c6ff6fb8f45.
NOTE: Session S2 is ACTIVE using port 5570 and host dvmictsas001.health.fgov.be for user dki. The session UUID is 
      13db7c51-6693-7c4b-8746-a9b2b45047f5.
NOTE: Session S3 is ACTIVE using port 5570 and host dvmictsas001.health.fgov.be for user dki. The session UUID is 
      8bba1ab2-6287-ee41-a8e0-05fdb1419acb.
89   
90   /*3. Use _CASNAME_ to check the active session. Looks OK */
91   %put We expect S3 &=_CASNAME_;
We expect S3 _CASNAME_=S3
92   
93   /*4. Assign caslib. Created for S3. Looks OK  */
94   libname casuser cas caslib=casuser;
NOTE: Libref CASUSER was successfully assigned as follows: 
      Engine:        CAS 
      Physical Name: 8bba1ab2-6287-ee41-a8e0-05fdb1419acb
95   
96   /*5. Terminate session S3  */
97   cas s3 terminate;
NOTE: Libref CASUSER has been deassigned.
NOTE: Deletion of the session S3 was successful.
NOTE: The default CAS session S3 identified by SAS option SESSREF= was terminated. Use the OPTIONS statement to set the SESSREF= 
      option to an active session.
NOTE: Request to TERMINATE completed for session S3.
98   
99   /*6. List the sessions - we can see 2 sessions. Looks OK  */
100  cas _ALL_ list ;
NOTE: Session S1 is ACTIVE using port 5570 and host dvmictsas001.health.fgov.be for user dki. The session UUID is 
      204a4f74-9c47-6541-a0e8-9c6ff6fb8f45.
NOTE: Session S2 is ACTIVE using port 5570 and host dvmictsas001.health.fgov.be for user dki. The session UUID is 
      13db7c51-6693-7c4b-8746-a9b2b45047f5.
101  
102  /*7. CASNAME is still S3, but I expect to see S2.  */
103  %put We expect S2 &=_CASNAME_;
We expect S2 _CASNAME_=S3
104  
105  /*8. Libname creates new cas session S3. I expect to see connection S2  */
106  libname casuser cas caslib=casuser;
NOTE: The session S3 connected successfully to Cloud Analytic Services dvmictsas001.health.fgov.be using port 5570. The UUID is 
      26cf8715-f5a8-ab4c-8792-d9873df8879a. The user is dki and the active caslib is CASUSER(dki).
NOTE: The SAS option SESSREF was updated with the value S3.
NOTE: The SAS macro _SESSREF_ was updated with the value S3.
NOTE: The session is using 0 workers.
NOTE: Libref CASUSER was successfully assigned as follows: 
      Engine:        CAS 
      Physical Name: 26cf8715-f5a8-ab4c-8792-d9873df8879a
107  
108  /*9. After the libname we again see 3 cas session. S3 was automatically created  */
109  cas _ALL_ list ;
NOTE: Session S1 is ACTIVE using port 5570 and host dvmictsas001.health.fgov.be for user dki. The session UUID is 
      204a4f74-9c47-6541-a0e8-9c6ff6fb8f45.
NOTE: Session S2 is ACTIVE using port 5570 and host dvmictsas001.health.fgov.be for user dki. The session UUID is 
      13db7c51-6693-7c4b-8746-a9b2b45047f5.
NOTE: Session S3 is ACTIVE using port 5570 and host dvmictsas001.health.fgov.be for user dki. The session UUID is 
      26cf8715-f5a8-ab4c-8792-d9873df8879a.
 

 

3 REPLIES 3
yabwon
Onyx | Level 15

According to a note from log:

Use the OPTIONS statement to set the SESSREF= option to an active session.

Maybe the option should be set first (before point 7)?

 

Bart 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



idziemianczyk
Obsidian | Level 7

Hi Bart, thanks for the response. For sure it will work if I set SESSREF.

 

With SESSREF= option we can assign CAS action for any of the opened sessions, there are no doubts about it.

The tricky part we don't know which session is chosen automatically when we haven't set the SESSREF explicitly. 

I would like to understand the logic of assigning the default SESSREF. 

 

yabwon
Onyx | Level 15

From the doc of SAS Help Center: CAS Statement

 

TERMINATE

terminates a single connected or disconnected session, or all of the connected and disconnected sessions in your SAS client.

Alias CLEAR
Notes When you terminate the active session, SAS system option SESSREF= continues to reference the terminated session. A note is written to the SAS log indicating that the session identified by SAS system option SESSREF= was terminated. To access the server in that case, you must start a new session or set system option SESSREF= to an existing connected session. See Start a Session and SESSREF= System Option in SAS System Options: Reference.
If you terminate a session that you disconnected using DISCONNECT, the disconnected session is removed from your client's session list, but it continues to run on the server until its time-out expires. To terminate the session in that case, see Terminating a Disconnected Session.
Tip Use this option with session-name to terminate a single connected or disconnected session, or use it with _ALL_ to terminate all of the currently connected and disconnected sessions in your SAS client.
See Terminate a Session

 

It looks like it updates the value with every "cas" statement execution, but do not updates it after terminating.

 

82     /*1. Create 3 cas sessions  */
83     %put &=_CASNAME_;
WARNING: Apparent symbolic reference _CASNAME_ not resolved.
_CASNAME_
84     cas s1;
NOTE: The session S1 connected successfully to Cloud Analytic Services yyyyyyyyyyy.exnet.sas.com using port 5571. The UUID is 
      9bf41b83-b09a-f14e-811f-c4135b70ed9f. The user is xxxxxxxxxxxxxxxxxxxxxx and the active caslib is 
      CASUSER(xxxxxxxxxxxxxxxxxxxxxx).
NOTE: The SAS option SESSREF was updated with the value S1.
NOTE: The SAS macro _SESSREF_ was updated with the value S1.
NOTE: The session is using 0 workers.
85     %put &=_CASNAME_;
_CASNAME_=S1
86     cas s2;
NOTE: The session S2 connected successfully to Cloud Analytic Services yyyyyyyyyyy.exnet.sas.com using port 5571. The UUID is 
      77b6afaf-fc52-5d41-a6ab-1e962a2df8d4. The user is xxxxxxxxxxxxxxxxxxxxxx and the active caslib is 
      CASUSER(xxxxxxxxxxxxxxxxxxxxxx).
NOTE: The SAS option SESSREF was updated with the value S2.
NOTE: The SAS macro _SESSREF_ was updated with the value S2.
NOTE: The session is using 0 workers.
87     %put &=_CASNAME_;
_CASNAME_=S2
88     cas s3;
NOTE: The session S3 connected successfully to Cloud Analytic Services yyyyyyyyyyy.exnet.sas.com using port 5571. The UUID is 
      9e3c1ab8-2a5f-014c-8ece-edd77f22ab0e. The user is xxxxxxxxxxxxxxxxxxxxxx and the active caslib is 
      CASUSER(xxxxxxxxxxxxxxxxxxxxxx).
NOTE: The SAS option SESSREF was updated with the value S3.
NOTE: The SAS macro _SESSREF_ was updated with the value S3.
NOTE: The session is using 0 workers.
89     %put &=_CASNAME_;
_CASNAME_=S3
90     
91     /*2. List the sessions - we can see 3 sessions. Looks OK  */
92     cas _ALL_ list ;
NOTE: Session S1 is ACTIVE using port 5571 and host yyyyyyyyyyy.exnet.sas.com for user xxxxxxxxxxxxxxxxxxxxxx. The session UUID 
      is 9bf41b83-b09a-f14e-811f-c4135b70ed9f.
NOTE: Session S2 is ACTIVE using port 5571 and host yyyyyyyyyyy.exnet.sas.com for user xxxxxxxxxxxxxxxxxxxxxx. The session UUID 
      is 77b6afaf-fc52-5d41-a6ab-1e962a2df8d4.
NOTE: Session S3 is ACTIVE using port 5571 and host yyyyyyyyyyy.exnet.sas.com for user xxxxxxxxxxxxxxxxxxxxxx. The session UUID 
      is 9e3c1ab8-2a5f-014c-8ece-edd77f22ab0e.

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1210 views
  • 0 likes
  • 2 in conversation