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

 

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!

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

 

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 863 views
  • 2 likes
  • 3 in conversation