Hi,
I have a folder with multiple SAS programs. I will like to run them all at one in parallel and not sequentially. In the past, I have opened multiple SAS Sessions and open each program on a different SAS Session and run them. This does the trick, but now I am having many more programs to run and I am looking for a simple code that I can have that will tell SAS to run the programs in that folder all at once in parallel sessions. Hope someone can help me.
Folder: \\myserver\myfolder
Programs:
prg1.sas
prg2.sas
prg3.sas
prg4.sas
If you are lucky enough to have SAS/CONNECT installed on your server then parallel processing is easy. See Example 5 in this link: https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=connref&docsetTarget=n11s...
If you use the systask it could be done with the BASE SAS only.
All the best
Bart
Hi,
this code should do the job:
%macro runInParallel(filesLocation);
/* get the list of files */
data filesWithCodes;
base = "&filesLocation.";
length file $ 256 folderRef fileRef $ 8;
folderRef = "_%sysfunc(datetime(), hex6.)0";
rc=filename(folderRef, base);
folderid=dopen(folderRef);
N = dnum(folderId);
do i=1 to N; drop i;
file = dread(folderId, i);
call symputX(cats("TEST_", i), file, "L");
output;
end;
rc = dclose(folderid);
rc = filename(folderRef);
call symputX("numberOfTests", N, "L");
stop;
run;
proc print data = filesWithCodes;
run;
/* setup SAS sessions */
%local SASROOT SASEXE SASWORK;
filename sasroot "!SASROOT";
%let SASROOT=%sysfunc(PATHNAME(sasroot));
filename sasroot;
%put *&SASROOT.*;
%let SASEXE=&SASROOT./sas;
%put *&SASEXE.*;
%let SASWORK=%sysfunc(GETOPTION(work));
%put *&SASWORK.*;
%local t;
systask kill
%do t = 1 %to &numberOfTests.;
sas&t.
%end;
wait;
/* run parallel jobs */
/* you can adjust the config file location yourself */
%do t = 1 %to &numberOfTests.;
%local sasstat&t.;
systask command
"""&SASEXE.""
-sysin ""&filesLocation./&&TEST_&t.""
-print ""&filesLocation./&&TEST_&t...lst""
-log ""&filesLocation./&&TEST_&t...log""
-config ""&SASROOT./sasv9.cfg""
-work ""&SASWORK.""
-noterminal
-rsasuser"
taskname=sas&t.
status=sasstat&t.
NOWAIT
;
%end;
waitfor _all_
%do t = 1 %to &numberOfTests.;
sas&t.
%end;
;
data _null_;
put "NOTE: The End!";
run;
%mend runInParallel;
options NOQUOTELENMAX;
%runInParallel(C:\Users\bart\Desktop\abc)
Test executed on the folder:
C:\Users\bart\Desktop\abc
which contains 3 files a.sas, b.sas, c.sas with the following code:
a:
data _null_;
rc = sleep(5,1);
put "A";
run;
b:
data _null_;
rc = sleep(3,1);
put "B";
run;
c:
data _null_;
rc = sleep(1,1);
put "C";
run;
all the best
Bart
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.