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/"
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
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
Thanks Chris. The UUIDGEN function is what I need. Found your blog post about it as well. Appreciate the help.
The SAS system uses the hexadecimally coded process number to create the WORK directory. Among other things, this makes it easy for the cleanwork utility to find orphaned directories.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.