SAS - Looping Efficiently

Posted on 2013-01-10
Medium Priority
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 2000 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

719 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