BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
bheinsius
Lapis Lazuli | Level 10

Hi,

 

In SAS Studio, how can I programmatically detect if I have an active CAS session?

I compared all macro variables and SAS options between the two situation but found nothing that indicates this.

 

Thanks,

Bart

1 ACCEPTED SOLUTION

Accepted Solutions
Panagiotis
SAS Employee

I did some more digging and I think I found the answer. I'll leave my previous post up since the macro variable might be useful to some.

 

But you can use the SESSFOUND Function: https://go.documentation.sas.com/doc/en/pgmsascdc/default/lefunctionsref/p1b4sxnrjxw5y8n1cadgqkdtz8h...

 

%put doIExist= %sysfunc(sessfound(add_sesion_name_here));

Returns a 0 when a CAS session is not connected to a server and a 1 when the session is connected to a server.

View solution in original post

4 REPLIES 4
Panagiotis
SAS Employee

I've found when you create a CAS Session it creates two macro variables(_SESSREF_ and _CASNAME_)  with the CAS session name.

However, if you terminate your CAS session or the CAS session times out, those macro variables still exist. So this might not be the best solution but a start.

 

Run the following code to check if the CAS session conn exists:

cas conn;

/* Check for a specific cas session */
%if &_SESSREF_=CONN %then %do; 
    %put 'Yes the macro variable of a cas session does exist';
%end;
%else %do;
    %put 'No CAS session';
%end;

Does this help?

 

What's your specific use case for this?

 

 

 

Panagiotis
SAS Employee

I did some more digging and I think I found the answer. I'll leave my previous post up since the macro variable might be useful to some.

 

But you can use the SESSFOUND Function: https://go.documentation.sas.com/doc/en/pgmsascdc/default/lefunctionsref/p1b4sxnrjxw5y8n1cadgqkdtz8h...

 

%put doIExist= %sysfunc(sessfound(add_sesion_name_here));

Returns a 0 when a CAS session is not connected to a server and a 1 when the session is connected to a server.

bheinsius
Lapis Lazuli | Level 10
That does the trick, thanks!
Panagiotis
SAS Employee

You're welcome! I just learned about this function. Great question!

 

- Peter