Help using Base SAS procedures

run sas scripts based on condition

Posts: 32

run sas scripts based on condition


I am trying to run write a script to mimic a scheduler.  If some conditions meet, then I would like to run certain SAS files.  I was playing around and I was able to write the code to run SAS files but this is not exactly what I am looking for.  The SAS programs need to run simultaneously or in parallel.


    %do i = 110 %to 151;

        PROC SQL noprint;


                INTO :ISINREADY, :ISPRG

                FROM &nkgds..MEDEXP_STG_READY_V

                WHERE PRG_SEQ=&i;


        %IF &ISINREADY =&I

            %THEN %DO;



                %include "&isprg";






There are about 30 programs.  My objective is that if their status is 'READY', the program can run without manual intervention.

The problem with the above code is that the next program only runs when the SAS program in the include function has completed.  Lot of these programs run for hours and totally independent from one another.  I'd like them to run simultaneously. 

I run this code in Unix.  I did try X command but lot of the macros are defined elsewhere, hence giving macro not defined error.  I looked for some suggestions, but my search did not result in any helpful topic.

I am sure there is a simple way to fix this.  I would be very grateful, if anybody could help me.

Thank you very much.



Super User
Posts: 10,269

Re: run sas scripts based on condition

I would not try to do the scheduling inside a SAS program, as this is clearly an operating system-level task.

The best option is to use some real scheduling system.

If you dont't have access to one in your company/organization, you could try to use cron and make in conjunction with a wrapper shell script for the sas programs.

The makefile would contain the conditions and actions based on semaphore files for the jobs, and the wrapper script would write the semaphores when completing a job successfully.

But the best option is to go for a real scheduling system.

Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Posts: 32

Re: run sas scripts based on condition

Posted in reply to KurtBremser

Thank you very much Kurt.  Eventually, I will have to play with the scheduler to schedule these jobs.

If the jobs were to run during a time period, then it would have been easy.  The jobs need to run when the data is ready.  This data is entered by the users manually.

I will have to find the macros used in these jobs, put them in a separate file and include them in the sas programs for the X command to run successfully.  I will give that a shot.



Super Contributor
Posts: 358

Re: run sas scripts based on condition


There are scheduling systems that can run your job based on whether a file has been created, AutoSys comes to mind.  Far superior than

trying to re-invent the wheel and build your own scheduler.


Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation