BookmarkSubscribeRSS Feed
ismahero2
Obsidian | Level 7

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

 

 

3 REPLIES 3
SASKiwi
PROC Star

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...

 

yabwon
Onyx | Level 15

If you use the systask it could be done with the BASE SAS only.

All the best

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

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
  • 3 replies
  • 1130 views
  • 3 likes
  • 3 in conversation