Solved

SAS - Looping Efficiently

Posted on 2013-01-10
4
354 Views
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.

Structure:

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
0
Comment
Question by:aruku
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
theartfuldazzler earned 500 total points
Comment Utility
Hi

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)
Random-job.sas
Controlling-job-anon-.sas
0
 

Author Comment

by:aruku
Comment Utility
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.
0
 
LVL 14

Expert Comment

by:Aloysius Low
Comment Utility
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;
  %do;
    proc sql;
      select count(1) into :count from [control table] where start_ind = 'N';
    quit;

    %if &count > 0 %then %do;
      [execute the job]]
    %end;
  %until &count = 0 end;
%mend;
%check_execute;
(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);
run;

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
0
 
LVL 11

Expert Comment

by:theartfuldazzler
Comment Utility
Hi

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;

WAITFOR _ANY_ SAS1 SAS2;

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.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction: I have seen many questions on EE and elsewhere, asking about how to find either gaps in lists of numbers (id field, usually) ranges of values or dates overlapping date ranges combined date ranges I thought it would be a good …
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now