BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AKHILA
Obsidian | Level 7

Hi all,

 

I have some 5 programs ,say for eg: pgm1.sas, pgm2.sas, pgm3.sas. etc which i am saving in the same location. let it be D:\Path.

Is there any way to use a  single %include statement to run all this programs at once?

 

Please help me for this.

 

1 ACCEPTED SOLUTION

Accepted Solutions
MCoopmans
SAS Employee

Maybe this is doing the trick:

 

%let path=c:\temp;


filename sasfiles "&path";

data files;
 
 did=DOPEN("sasfiles");
 do i=1 to DNUM(did);
  name=dread(did,i);
  ext=SUBSTR(name,INDEX(name,".")+1);
  path="&path\" ||name ;
  if UPCASE(ext)="SAS" then do;
    output;
	call execute ("%include '"|| path  || "';");
    *put name= ext=;
	end;
 end;
run;

View solution in original post

12 REPLIES 12
Patrick
Opal | Level 21

With "at once" do you mean "in parallel"?

AKHILA
Obsidian | Level 7

I mean simply to run all 5 pgms parellel or one after other to get the 5 outputs.

gamotte
Rhodochrosite | Level 12

Hello,

 

Something like this ?

 

filename a ("c:/temp/a.sas" "c:/temp/b.sas");

%include a;
Patrick
Opal | Level 21

If what you're asking for here is not just a "dumed-down" version of your real problem then just having five %include statements is by far the easiest and easiest to maintain option.

 

If the real problem you want to solve is of higher complexity then please share. 

Kurt_Bremser
Super User

You can use one %INCLUDE statement by specifying the "aggregate storage location" (in this case, a directory) first:

filename progdir "D:\Path";

%include progdir(pgm1,pgm2,pgm3,pgm4,pgm5);

Note that this will run the included codes in succession.

If you want to run several SAS programs simultaneously, you need to run several SAS sessions in parallel.

AKHILA
Obsidian | Level 7

Thanks for the suggestion. but in future if i add more programs how can i dynamically add those without entering in %include statement.

 

Can you please suggest some macros?

Kurt_Bremser
Super User

How do you add your programs? If you simply put them into a specific directory, and all programs in that directory need to be run, then @MCoopmans's code will do the trick.

 


@AKHILA wrote:

Thanks for the suggestion. but in future if i add more programs how can i dynamically add those without entering in %include statement.

 

Can you please suggest some macros?


 

Jagadishkatam
Amethyst | Level 16
Instead of %include, you can use the batch file to run , please let me know if your sas session is in unix/linux
Thanks,
Jag
MCoopmans
SAS Employee

Maybe this is doing the trick:

 

%let path=c:\temp;


filename sasfiles "&path";

data files;
 
 did=DOPEN("sasfiles");
 do i=1 to DNUM(did);
  name=dread(did,i);
  ext=SUBSTR(name,INDEX(name,".")+1);
  path="&path\" ||name ;
  if UPCASE(ext)="SAS" then do;
    output;
	call execute ("%include '"|| path  || "';");
    *put name= ext=;
	end;
 end;
run;
PaigeMiller
Diamond | Level 26

Does the order the programs are run make a difference? Or will any order work?

--
Paige Miller
AKHILA
Obsidian | Level 7

any order is fine

Ksharp
Super User
Not sure if the following could work.

%include "D:\Path\pgm*.sas" ;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 12 replies
  • 8425 views
  • 5 likes
  • 8 in conversation