Desktop productivity for business analysts and programmers

Multiple Sessions at the same time

Accepted Solution Solved
Reply
Contributor
Posts: 70
Accepted Solution

Multiple Sessions at the same time

I have a model on SAS which is running 5 stored process programs and it is made with a lot of macros, one among them is a macro for Library name so that different users can work in their Library but here I am facing a problem as if multiple users run the Model at the same time or a single user opens two SAS sessions and runs the model on both the sessions then the Model conflicts because the Macro Variable conflicts.

Is there a way that different users or single user with multiple sessions can run the programs at the same time without conflicting with each other.

 

I hope someone can help with this problem.

 

I was wondering if one can use the SAS session ID or WIndows session ID or something like that to distinguish between the sessions.


Accepted Solutions
Solution
‎08-04-2017 02:27 AM
Respected Advisor
Posts: 4,137

Re: Multiple Sessions at the same time

[ Edited ]

@DipeshGupta

If I understand your problem correctly then you need a table metadata definition to define the prompt but during runtime you need this metadata table to be linked to user specific physical data.

If so then the way I've solved this in the past:

1. In Metadata define the Library and the Table Metadata 

2. During runtime issue a libname statement with the same libref than the one defined in metadata but now use a user specific path.

    - I've implemented this user specific "overwrite" libname in the autoexec but I guess you could also do it in the SP code.

    - My path for the Metadata libname definiton was something like "dummy, defined in autoexec" to make the approach clear

 

 

 

View solution in original post


All Replies
Super User
Posts: 7,444

Re: Multiple Sessions at the same time

Use only WORK for temporary data.

If you need to write to a specific permanent dataset (or external file), then you must make sure that only one instance of the STP can be active at any given time.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 7,444

Re: Multiple Sessions at the same time

Use only WORK for temporary data.

If you need to write to a specific permanent dataset (or external file), then you must make sure that only one instance of the STP can be active at any given time.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
PROC Star
Posts: 1,146

Re: Multiple Sessions at the same time

First step, follow @KurtBremser's advice and use WORK as much as possible. I would also hive off anything that's read-only, and store it in a common library that is used by all users.

 

And finally, if there are any datasets left that need to be created or modified, but can't be placed in WORK, the &SYSPROCESSID automatic macro variable can be used to get the process ID of the current SAS process.

 

Tom

Contributor
Posts: 70

Re: Multiple Sessions at the same time

@KurtBremser I can use the work library but the problem is if I use the work library then when the second STP program runs it is not able to get the temporary datset created by the first STP program may be because at the end of the STP program all its temporary memory is cleared.

Respected Advisor
Posts: 4,137

Re: Multiple Sessions at the same time

[ Edited ]

@DipeshGupta

To implement user specific permanent libraries you could use code as below:

options dlcreatedir;
libname myseslib "c:\temp\&SYSUSERID";

The SAS9.4 option DLCREATEDIR will create the folder used in the libname path if it doesn't exist already (works only for the last folder in the path). This would allow for user specific folders.

 

For session specific folders:

I can't really think of a case where you wouldn't just want to use WORK unless you need to keep the data sets after the session ends. But then you'd have to find the session specific folder so not really sure if that's so helpful. 

You could implement such libraries creating the necessary folders on-the-fly as shown below:

options dlcreatedir;
libname MyLib "c:\temp\&SYSUSERID";
libname MyLib "c:\temp\&SYSUSERID\&SYSPROCESSID";

 

Oh... and for the case where a single user executes a model "in parallel" in multiple sessions:

You could create session specific table names if it's about code trying to overwrite tables. If it's just about apending results to a common table and to avoid table locking issues then eventually using option FILELOCKWAIT will suffice.

http://support.sas.com/documentation/cdl/en/hostunx/69602/HTML/default/viewer.htm#p1006eif9dw75bn1c7...

 

 

Contributor
Posts: 70

Re: Multiple Sessions at the same time

@Patrick For the case where a single user executes a model "in parallel" in multiple sessions:

I think creating session specific table name will work.

 

And I didn,t understand this -> 

 

If it's just about apending results to a common table and to avoid table locking issues then eventually using option FILELOCKWAIT will suffice.

Contributor
Posts: 70

Re: Multiple Sessions at the same time

And is there a way to use Windows Session ID to control SAS instead of using SAS userID and SAS Process ID..??

Super User
Posts: 3,237

Re: Multiple Sessions at the same time

A good way to do parallel processing in multiple SAS sessions is by using SAS/CONNECT and its asynchronous capabilities. This link shows some of the possibilities:

 

http://support.sas.com/rnd/scalability/tricks/connect.html

 

SAS/CONNECT enables you to do all of the processing in WORK libraries then to download the required data to your controlling SAS session when complete. Your controlling SAS session can also wait until all of the child SAS sessions have completed.

 

Of course you do need SAS/CONNECT to be installed and licensed on your SAS server to do this.

Super User
Posts: 7,444

Re: Multiple Sessions at the same time

The problem of two users running the same STP in parallel is one I would solve quite easily: The second instance crashes because of the locked file, and when the user complains he/she gets a nastygram about over-using shared resources. You only run one STP at a time, period.

As soon as that is established, I make sure that each user uses an individual library (something like USER defined in their home directory), so their chain of STPs can hand over data without coming into conflict with the other users.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 70

Re: Multiple Sessions at the same time

I am facing another problem and this time its not about SAS Library but SAS Folders. Each user has its own unique library where the data is stored but how to create unique SAS Folders because the STP has many dynamic prompts which conflicts when different user run the program because dynamic prompts work through SAS Folders and I guess a SAS Folder is created through SMC so how can I create SAS Folders through code so that each user and each session has its unique SAS Folder.

Regular Contributor
Posts: 171

Re: Multiple Sessions at the same time

Would it be possible to set different permissions on the various Metadata folders so that folders that a user doesn't have access to become 'invisble' ?

Contributor
Posts: 70

Re: Multiple Sessions at the same time

Sorry but I don't know whether it is possible or not but even if it is possible, I don't think it will solve the problem because still different users will need unique folders to run the STP

Super Contributor
Posts: 396

Re: Multiple Sessions at the same time

There's a SAS Interface to Metadata that you might be able to use - the metadata_newobj function can create metadata objects. I'd advise extreme caution in developing and testing it though as programatically altering metadata could turn into a nightmare.

 

The link to the documentation is here

Solution
‎08-04-2017 02:27 AM
Respected Advisor
Posts: 4,137

Re: Multiple Sessions at the same time

[ Edited ]

@DipeshGupta

If I understand your problem correctly then you need a table metadata definition to define the prompt but during runtime you need this metadata table to be linked to user specific physical data.

If so then the way I've solved this in the past:

1. In Metadata define the Library and the Table Metadata 

2. During runtime issue a libname statement with the same libref than the one defined in metadata but now use a user specific path.

    - I've implemented this user specific "overwrite" libname in the autoexec but I guess you could also do it in the SP code.

    - My path for the Metadata libname definiton was something like "dummy, defined in autoexec" to make the approach clear

 

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 15 replies
  • 679 views
  • 1 like
  • 7 in conversation