Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 442
  • Last Modified:

SAS - Looping Efficiently

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
aruku
Asked:
aruku
  • 2
1 Solution
 
theartfuldazzlerCommented:
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
 
arukuAuthor Commented:
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
 
Aloysius LowCommented:
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
 
theartfuldazzlerCommented:
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now