SAS - Looping Efficiently

Posted on 2013-01-10
Last Modified: 2013-03-07
Hi experts,

I have a queue list and daily around 70 jobs gets added to the queue and i have around 15 threads of SAS scripts as task list. The scripts will take the jobs in the queue list by row no. and run a loop till all the 70 jobs are complete.


Job name   row_no   start_ind    end_ind     task_no

job1               1              N                   N              -999

The job will first start with updating start_ind to 'Y' and after completion changes end_ind to 'Y'. The task_no will be updated by SAS thread no.

The issue is, if all the 70 are occupied by 15 jobs and there is no N, N, -999. The completed threads are still running the loop and checking each and every queue. Can i avoid that?

Please respond
Question by:aruku
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 11

Accepted Solution

theartfuldazzler earned 500 total points
ID: 38766325

From what i understand - you have around 70 jobs to run daily, but only 15 "slots" at any point in time, and you need to allocate a new job once another job has finished?

What wasn't covered in your question - what is the controlling process of the SAS jobs?  Are you running a SAS job with rsubmit statements?  If you are - can you send some of the code?

If you are doing asyncronous rsubmit processing - then you can use WAITFOR _ANY_ and WAITFOR _ALL_ commands in your code.

I've written some code (but it is quite complex - as its full of SAS macros), but it does the job... See attached files. Hopefully you can apply it to your needs.

The big changes you would need to make, would be the specific IP address and signon parameters for your SAS Server (or local box)

Author Comment

ID: 38768969
Thanks for the response artfuldazzler!!

All the 15 slots are different SAS wrapper codes, so am not using any rsubmit commands.

I am using %do loop, so if there are no jobs to perform the jobs are just running to check if there is any availability. I would like to aviod that.
LVL 14

Expert Comment

by:Aloysius Low
ID: 38769088
so do you mean to say if there are no more jobs to run you want the wrapper code to terminate? if so, you could set a condition to check if there are more jobs to execute and to proceed only if there is e.g.

%let count = 1;
%macro check_execute;
    proc sql;
      select count(1) into :count from [control table] where start_ind = 'N';

    %if &count > 0 %then %do;
      [execute the job]]
  %until &count = 0 end;
(the logic is not tested, but the idea is there)

but question would be, who is going to restart the wrapper codes? if there is a scheduler that kick starts the wrapper codes at a certain time of the day, the above method would be fine.. however, if the wrapper codes are meant to be running, and you would like it NOT to constantly check the control table every split second, then i would recommend the SLEEP function, which tells the SAS code to wait for the stated number of unit of time before waking up to check again. To use the sleep function:

data _null_;
x = sleep(600, 1);

in this eg, it will make the SAS code run the data _null_ step for 600 seconds before waking up again.

hope either way helps to solve your problem
LVL 11

Expert Comment

ID: 38773417

I'm not sure how you are doing the SAS wrapper codes?

If you are using an X statement to run the SAS codes, then you can also use the WAITFOR _ANY_ command, by changing the X statement to a

SYSTASK COMMAND "[i]sas command 1[/i]"  TASKNAME=SAS1 STATUS=Busy1;
SYSTASK COMMAND "[i]sas command 2[/i]"  TASKNAME=SAS2 STATUS=Busy2;


Open in new window

The WAITFOR statement will wait until either of the jobs are complete, and the Busy1 or Busy2 will show which job has finished.

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question