BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DipeshGupta
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@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

15 REPLIES 15
Kurt_Bremser
Super User

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.

Kurt_Bremser
Super User

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.

TomKari
Onyx | Level 15

First step, follow @Kurt_Bremser'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

DipeshGupta
Calcite | Level 5

@Kurt_Bremser 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.

Patrick
Opal | Level 21

@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...

 

 

DipeshGupta
Calcite | Level 5

@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.

DipeshGupta
Calcite | Level 5

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

SASKiwi
PROC Star

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.

Kurt_Bremser
Super User

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.

DipeshGupta
Calcite | Level 5

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.

nhvdwalt
Barite | Level 11

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' ?

DipeshGupta
Calcite | Level 5

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

ChrisBrooks
Ammonite | Level 13

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

Patrick
Opal | Level 21

@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

 

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 15 replies
  • 8261 views
  • 2 likes
  • 7 in conversation