Help using Base SAS procedures

Scheduling SAS Queries

Reply
Frequent Contributor
Posts: 117

Scheduling SAS Queries

Hi Everyone,

I am a new SAS user and I run 6 seperate sas files on a monthly basis.

file1.sas ---> file6.sas

I have to run these files in a particular sequence and currently, I do this manually.

Is there any way I can setup automation which will run the sas files in the order I want monthy?

Thanks.

PROC Star
Posts: 7,363

Re: Scheduling SAS Queries

You are asking multiple questions and the answers may be dependent upon the type of system you are on.

You can always just have a driver program that has 6 %include statements, like:

%include "file1.sas";

%include "file2.sas";

%include "file3.sas";

%include "file4.sas";

%include "file5.sas";

%include "file6.sas";

and then save that as a seventh program.  As for running it monthly, if you are on Windows, I've had good success using Window's Scheduler.

Frequent Contributor
Posts: 117

Re: Scheduling SAS Queries

I am running on Windows 7 and SAS 9.2

I am assuming that I create a new SAS file and put those statements in there. Then Schedule that newly created file in task scheduler?

Respected Advisor
Posts: 3,124

Scheduling SAS Queries

I would first try to use %include.

for example:

%include "c:\file1.sas";

%include "c:\file2.sas";

...

%include "c:\file6.sas";

Regards,

Haikuo

Frequent Contributor
Posts: 117

Scheduling SAS Queries

Thanks HaiKuo and Art! I will give this a try and report back.

You guys are amazing Smiley Happy

PROC Star
Posts: 7,363

Scheduling SAS Queries

Plus, here is a nice paper that addresses a number of issues you may or may not have thought about:

http://analytics.ncsu.edu/sesug/2010/BB02.Zimmerman.pdf

Trusted Advisor
Posts: 2,113

Scheduling SAS Queries

One thing that Art and Haikou didn't mention is that the %include approach will give you one giant log file unless you use PROC PRINTTO to redirect it within each program.

An alternate approach is to create a Windows batch file that contains the SAS execution command and put that in once for each program.  You can find the syntax for your particular configuration by looking at the file association with the batch submission.  (I don't have windows 7, but in XP, it is in the windows explorer --> fools --> folder options --> file types and then go to SAS and click advanced and edit for the batch command.  You can also find the options in the SAS Companion for Windows.).

Doc Muhlbaier

Duke

Super User
Posts: 5,082

Re: Scheduling SAS Queries

vomer,

Here are two more considerations.  First, look at whether the option SOURCE2 is in place or not.  It determines whether %included lines get printed to the log or not.  That can nearly double the size of the log so you may want to turn it off.

Second, it's possible from your post that each job depends on the one before completing successfully.  If that's the case, you could modify the program:

%macro all_6_jobs;

   %include  'C:\file1.sas';

   %if &syserr=0 %then %include 'C:\file2.sas';;

   %if &syserr=0 %then %include 'C:\file3.sas';;

   %if &syserr=0 %then %include 'C:\file4.sas';;

   %if &syserr=0 %then %include 'C:\file5.sas';;

   %if &syserr=0 %then %include 'C:\file6.sas';;

%mend all_6_jobs;

%ALL_6_JOBS

Look up the possible values for &SYSERR to see if requiring 0 is too stringent for your purposes.  There are other slightly less strict possibilities.

Good luck.

Regular Contributor
Posts: 233

Scheduling SAS Queries

This can be acheived using crontab from Unix prompt. If you have access to unix log in and type crontab -e to check access.

Next you need to create a shell script to invoke the SAS program and schedule it from crontab using the format below. I have been doing this for a while this has reduced lot of manual effort.

Syntax for crontab:

Minute   Hour   Day of Month       Month          Day of Week        Command

Ask a Question
Discussion stats
  • 8 replies
  • 373 views
  • 6 likes
  • 6 in conversation