Solved

SAS - Looping Efficiently

Posted on 2013-01-10
4
383 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
ID: 38766325
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
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.
0
 
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;
  %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
ID: 38773417
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 Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
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…

831 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