BookmarkSubscribeRSS Feed
LineMoon
Lapis Lazuli | Level 10

Dear expert,

Having a several sas programs ordred as Follow :

Folder_1/1_Test.sas

             /2_PGM.sas

 

Folder_2/1_PGM.sas

               /2_PM.sas

I want to 

1) Create a main program for all sas program like this( the program order is important):

%include /Dir/Dir1/ Folder_1/1_Test.sas

 

2) create a log file for every program

 

3) analyze the files log in order to find: ERROR, Warning, _ORROR_

 

Thank you in advance

8 REPLIES 8
Tom
Super User Tom
Super User

Are you running SAS on Unix or Windows? (or IBM mainframe?)

Are you trying to run all of the programs in a single SAS session?

Or do you want to run them completely independently of each other?

 

The last is the best as then you don't have to play games with re-directing the log or worry about mistakes in one program putting SAS into strange state or programs only working because of side effects level over from the previous program.

 

So you probably just want to create an operating system command file to run the commands.

So on Unix it would look something like:

cd /..../Folder_1
sas 1_Test.sas
grep ^ERROR.*: 1_Test.log
sas 2_PGM.sas
grep ^ERROR.*: 2_PGM.log
cd /.../Folder_2
...
LineMoon
Lapis Lazuli | Level 10

Thank you very much.
It will run for all Operating System (not only unix) and in one sas session.
I want some thing automatic, linkg to all sas programs, keeping the programs order, create a log files and analysis the error and warning by program

Sajid01
Meteorite | Level 14

@LineMoon 
While the overall logic will be same (as given by @Tom ) irrespective of the operating system, the actual implementation / scripting will be different.
If you want to use an OS independent solution then better to write a SAS program to serve the purpose.

Tom
Super User Tom
Super User

@LineMoon wrote:

Thank you very much.
It will run for all Operating System (not only unix) and in one sas session.
I want some thing automatic, linkg to all sas programs, keeping the programs order, create a log files and analysis the error and warning by program


As I said that will introduce a lot more complications.  Once you have run one of the programs the others can never be sure what state SAS is in when they start.  So your system will be more fragile and require more complications.

 

If you just want to run all of the programs in one SAS job you could do something like:

filename dir1 '/..../Folder_1';
%include dir1('*.sas') / source2;

If you are saying you want to write the part of the SAS log generated by each file to separate locations that will require a lot more work.  You either have to have a dataset with the list of program files, or use code to generate the list by reading the directory.

 

So say you created a dataset name FILES with a variable named PROGRAM you might use that to generate code like this:

filename code temp;
data _null_;
  set files ;
  file code;
  log=program;
  log=tranwrd(log,'.sas','.log');
  put 'proc printto log=' log :$quote. ';run;'
    / '%include ' program :$quote. ';'
    / 'proc printto log=log; run;'
  ;
run;
%include code / source2;
LineMoon
Lapis Lazuli | Level 10
Thank you very much
Kurt_Bremser
Super User

So your company/institution runs multiple SAS servers on multiple different operating systems (also implying multiple SAS licenses)? This is quite unique.

LineMoon
Lapis Lazuli | Level 10
In this case, I can use sas with the unix commands
Kurt_Bremser
Super User

@LineMoon wrote:

Thank you very much.
It will run for all Operating System (not only unix) and in one sas session.
I want some thing automatic, linkg to all sas programs, keeping the programs order, create a log files and analysis the error and warning by program


This is called scheduling. Your company/institution will already have such in place; consult the admins how to integrate your SAS programs there.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 8 replies
  • 688 views
  • 1 like
  • 4 in conversation