BookmarkSubscribeRSS Feed
Yeti
Calcite | Level 5

Greetings,

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.

%MACRO RUN_READY();

    %do i = 110 %to 151;

        PROC SQL noprint;

            SELECT PRG_SEQ , TRIM(RUN_DIR)||TRIM(PROGRAM_NME) AS PRG   

                INTO :ISINREADY, :ISPRG

                FROM &nkgds..MEDEXP_STG_READY_V

                WHERE PRG_SEQ=&i;

        QUIT;

        %IF &ISINREADY =&I

            %THEN %DO;

                %NKG_SLEEP(5);

                %START_STG_T(&I);

                %include "&isprg";

               

            %END;

    %end;

    %NKG_SLEEP(2);

%MEND RUN_READY;

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.

Sincerely,

Naresh

3 REPLIES 3
Kurt_Bremser
Super User

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.

Yeti
Calcite | Level 5

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.

Cheers,

Naresh

OS2Rules
Obsidian | Level 7

Yeti:

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.

Regards.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1030 views
  • 0 likes
  • 3 in conversation