BookmarkSubscribeRSS Feed
suhas1
Calcite | Level 5

Hi,

 

i have 20 sas codes saved in c:/fc/sascd1.sas paricular location.

how i have to execute all sas codes at a time.

 

Thanks

 

10 REPLIES 10
PeterClemmensen
Tourmaline | Level 20

Do you want to run them in any specific order?

suhas1
Calcite | Level 5

hi,

 

i have to run those sas codes one after another

how to do in sas programming?

Kurt_Bremser
Super User

@suhas1 wrote:

hi,

 

i have to run those sas codes one after another

how to do in sas programming?


Is there a specific order, or do we simply run all .sas files in a directory as retrieved with a directory listing?

If there is an order, create a dataset with the program names and do

data _null_;
set myprograms;
call execute(cats('%include "',progname,'";'));
run;
suhas1
Calcite | Level 5

 

HI,

 

i have all sascode files saved in c drive.

i have to run all sascodes files one by one automatically.

 

Thanks.

 

Kurt_Bremser
Super User

@suhas1 wrote:

 

HI,

 

i have all sascode files saved in c drive.

i have to run all sascodes files one by one automatically.

 

Thanks.

 


See my code example.

Patrick
Opal | Level 21

@suhas1 

The easiest way to execute SAS code stored in an external SAS file is to use an %include statement. This just makes the code available to the programs you're running. If using multiple %include statements then it executes everything sequentially in a single SAS session - exactly in the same way it would if you'd copied all the code into a single file.

%include 'c:\<some path>\myprog1.sas' / source2;
%include 'c:\<some path>\myprog2.sas' / source2;
%include 'c:\<some path>\myprog3.sas' / source2;

To include external .sas files they must be accessible from the location where SAS executes (your SAS server). As you write "c-drive" I assume these .sas files are on your local machine and though you will need a local SAS installation for things to work.

 

Kurt_Bremser
Super User

On a UNIX system, I'd have a script like

cd /location
for PNAME in *.sas
do
  /sasconf/Lev1/SASApp/BatchServer/sasbatch.sh /location/$PNAME
done

On a Windows system, you do the same (logically), but the shell script syntax will be different (unless you have bash available).

Jagadishkatam
Amethyst | Level 16
I am not sure what you mean to execute all sas codes at a time, since the sas session is only once you can execute the sas codes one after another in the order of the sas codes, but cannot execute all at once.

If you meant to execute all sas codes in a location one after another you can batch submit the codes via unix/linux session, hope you are working in unix/linux environment.

The way to do this is as follows
prepare a batch file with .sh extension where you have the sas filenames one after another as below

sas file1.sas
sas file2.sas
sas file3.sas

and then from the unix terminal run the file with sh command

sh file.sh
Thanks,
Jag
Shmuel
Garnet | Level 18

What do you mean by sas code ?

How are the sas codes organized in the c:/fc/sascd1.sas ?

c:/fc/sascd1.sas is one file - is it an example out of 20 files or one file that contains all 20 sas codes?

Is sas code a macro program or not ? are all sas codes macro programs ?

 

 

Ksharp
Super User
%include 'c:\<some path>\*.sas' / source2;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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