Hi, I'm using SAS 9.4 M2 and I have the following problem. I'm running the below code and I cannot get the stpsrv_session -function to return (set) the variable values for _THISSESSION and _SESSIONID.
file _webout;* html output;
if libref('SAVE') ne 0 then rc = stpsrv_session('create');
%put THISSESSION = &_THISSESSION;
%put SESSIONID = &_SESSIONID;
--> The variable values are not set and I get:
WARNING: Apparent symbolic reference _SESSIONID not resolved. _SESSIONID = "&_SESSIONID."
WARNING: Apparent symbolic reference _THISSESSION not resolved. _THISSESSION = "&_THISSESSION."
I'm running the above code as a stored process with the code below. And I am not getting any error messages (except for the mentioned warnings).
proc stp program='/example_directory/stpsrv_session';
outputfile _webout = '/example_directory/webout.html';
My first thought is try moving your %PUT statements after the RUN; statement that ends your DATA step. As written, the %PUT statement is executed before the data step code to create the session is executed.
You can also create a session with just the macro language, e.g.:
%let rc=%sysfunc(stpsrv_session(create)); %put &_ThisSession;
Yes, looks like stored process sessions are only available on the stored process server, not the workspace server. See e.g. : http://support.sas.com/documentation/cdl/en/stpug/68399/HTML/default/viewer.htm#p1lxbssuprk9vln17qbw...
Quentin is correct about the placement of the %PUT statements:
data _null_; if (libref('SAVE') ne 0) then rc = stpsrv_session('create'); run; %put &=_THISSESSION; %put &=_SESSIONID;
His code should work, too.
He's also correct about sessions not being supported by the SAS Workspace Server. These messages are written to the SAS log when you run the test code on a workspace server:
ERROR: STP No session scope available.
NOTE: STP sessions cannot be used with Workspace servers.
Check the value of the SYSPROCESSMODE macro variable to determine the type of server. The variable has a value of either Stored Process Server or SAS Workspace Server.
Sorry to hijack this thread but I think this question is relevant enough for the OP. It's also one I've been arguing about with a colleague for a couple of weeks now, but haven't got round to testing yet. The documentation on this subject states the following:
A session exists in the server process where it was created. All stored processes that access that session must execute in the same server process. Load balancing and other execution dispatching features are typically ignored when using sessions that might have an impact on application performance and scalability.
Does this mean that when a session is created when a particular client executes a session-using STP, the normal load balancing for subsequent requests is ignored and some kind of session affinity for that multibridge process takes precedence over the LB for connections from that client? Or does the client continue to get redirected to available multibridge processes by the spawner as usual depending on the configured load balancing algorithm, and the session will only be reused if the request lands on the same multibridge process where the session was initially saved?
Hope that makes sense. Maybe it's just me but the way that paragraph is worded could suggest either of those...
@mansour_ibrahim - you can use the `SYSPROCESSMODE` macro variable.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.