I've done the following on my own system without seeming problems. I can't recall when I verified it. Similar code is going to be to run in a server environment and I don't have access to system commands to verify.
<session starts>
/* set up a temporary (work) folder isolated from the main work folder */
%let path = %sysfunc(DCREATE(isolate,%sysfunc(pathname(WORK)))) ;
%let isolate = %sysfunc(pathname(WORK))/isolate ; /* dont use &path in case code is rerun in session... */
libname ISOLATE "&isolate" ;
/* create stuff in ISOLATE ;
* create stuff in WORK ;
* compare, contrast and twiddle data betwixt the two ;
*/
libname ISOLATE ;
<session ends>
Will SAS remove the .../isolate sub-folder as well as every file in the then work folder?
I rely on this behavior all of the time when I use DLCREATDIR and LIBNAME to make temp folders, like this:
options dlcreatedir;
%let repopath=%sysfunc(getoption(WORK))/wordle-sas;
libname repo "&repopath.";
data _null_;
rc = gitfn_clone(
"https://github.com/sascommunities/wordle-sas",
"&repoPath."
);
put 'Git repo cloned ' rc=;
run;
%include "&repopath./wordle-sas.sas";
/* start a game and submit first guess */
%startGame;
%guess(adieu);
One cool thing about this technique is that you can use a concatenated LIBNAME to create multiple folders.
options dlcreatedir;
%let outdir=%sysfunc(getoption(WORK));
libname res ("&outdir./results", "&outdir./results/images");
libname res clear;
I don't really know the answer, but YOU could try it yourself and find out the answer in seconds! Please let us all know what the answer is.
Maxim 4: If in doubt, do a test run and look at the results.
In general yes. At least it has in every installation I have used.
You could try it yourself. Run your program, make sure the actual path is printed into the SAS log, and then check if the folder is gone after the job ends.
Note there is a SAS option to disable the automatic removal of the WORK directory. So make sure you don't have that option set.
It did for me with a manually-created folder done via Windows Explorer. I don't think a DCREATE'd folder would behave any differently.
I've used this approach in various environments over the years and never observed any issues. Based on experience I'd say that when SAS terminates a session it always removes the work folder and all its content irrespective of its content.
I rely on this behavior all of the time when I use DLCREATDIR and LIBNAME to make temp folders, like this:
options dlcreatedir;
%let repopath=%sysfunc(getoption(WORK))/wordle-sas;
libname repo "&repopath.";
data _null_;
rc = gitfn_clone(
"https://github.com/sascommunities/wordle-sas",
"&repoPath."
);
put 'Git repo cloned ' rc=;
run;
%include "&repopath./wordle-sas.sas";
/* start a game and submit first guess */
%startGame;
%guess(adieu);
One cool thing about this technique is that you can use a concatenated LIBNAME to create multiple folders.
options dlcreatedir;
%let outdir=%sysfunc(getoption(WORK));
libname res ("&outdir./results", "&outdir./results/images");
libname res clear;
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.