BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
RJo
Fluorite | Level 6 RJo
Fluorite | Level 6

I'm interested in using the &SASWORKLOCATION macro variable to create a unique ID. It seems like a portion of this macro variable is unique and created the first time a data set is saved to the work library. If you close and re-open the EG project, then re-run code to create something in the work library, a new value for this macro variable is created. Here is an example of my code and the log. I'm specifically interested in the part in blue. Is it in fact unique or could this portion of the work library directory get re-used for another EG project at another time? (Note - I scrambled some of the values to make sure I don't inadvertently post any sensitive information.)

 

Thanks!

 

Run this code:

data test;

length testvar $10;

run;

%put &SASWORKLOCATION;

 

Log:

30         %put &SASWORKLOCATION;

"/saswork/SAS_workAB9C00005740_xxxxxxx.xxxx.net/SAS_work325100115740_xxxxxxx.xxxx.net/"

 

Save, close, re-open the EG project, re-run the same code. Now the log shows:

30         %put &SASWORKLOCATION;

"/saswork/SAS_workF0R900007C73_xxxxxxx.xxxx.net/SAS_work2FB622007C73_xxxxxxx.xxxx.net/"

 

Just re-running the code without closing the EG project, the directory does not change:

30         %put &SASWORKLOCATION;

"/saswork/SAS_workF0R900007C73_xxxxxxx.xxxx.net/SAS_work2FB622007C73_xxxxxxx.xxxx.net/"

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

The WORK folder (location of the WORK library and other transient files) is established when your SAS session starts. The root is determined from the WORK system option you specify at startup or in a config file (an admin does this).

 

When you start EG and run a project, a SAS session is established. When you run another project that session is reused (same WORK folder) unless you close EG (which closes all SAS sessions) or explicitly select Disconnect from the Servers list. A new session would then have a new WORK folder.

 

If your goal is to create a folder with a truly unique name, something like this would do it:

 

options dlcreatedir;
%let path=%sysfunc(getoption(WORK))/%sysfunc(uuidgen());
/* creates folder AND assigns a libname of P */
libname p "&path";

 

Output:

28         options dlcreatedir;
29         %let path=%sysfunc(getoption(WORK))/%sysfunc(uuidgen());
30         /* creates folder AND assigns a libname of P */
31         libname p "&path";
NOTE: Library P was created.
NOTE: Libref P was successfully assigned as follows: 
      Engine:        V9 
      Physical Name: /sastmp/SAS_workF20600013E2E_miseiddvp1/SAS_work0BC600013E2E_miseiddvp1/01ecb587-154b-2648-b97e-70cbe712106b

 

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

View solution in original post

4 REPLIES 4
ChrisHemedinger
Community Manager

The WORK folder (location of the WORK library and other transient files) is established when your SAS session starts. The root is determined from the WORK system option you specify at startup or in a config file (an admin does this).

 

When you start EG and run a project, a SAS session is established. When you run another project that session is reused (same WORK folder) unless you close EG (which closes all SAS sessions) or explicitly select Disconnect from the Servers list. A new session would then have a new WORK folder.

 

If your goal is to create a folder with a truly unique name, something like this would do it:

 

options dlcreatedir;
%let path=%sysfunc(getoption(WORK))/%sysfunc(uuidgen());
/* creates folder AND assigns a libname of P */
libname p "&path";

 

Output:

28         options dlcreatedir;
29         %let path=%sysfunc(getoption(WORK))/%sysfunc(uuidgen());
30         /* creates folder AND assigns a libname of P */
31         libname p "&path";
NOTE: Library P was created.
NOTE: Libref P was successfully assigned as follows: 
      Engine:        V9 
      Physical Name: /sastmp/SAS_workF20600013E2E_miseiddvp1/SAS_work0BC600013E2E_miseiddvp1/01ecb587-154b-2648-b97e-70cbe712106b

 

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
RJo
Fluorite | Level 6 RJo
Fluorite | Level 6

Thanks Chris. The UUIDGEN function is what I need. Found your blog post about it as well. Appreciate the help.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2227 views
  • 2 likes
  • 3 in conversation