Assuming I have a code that is scheduled to run every 15 minutes(see attached file for my table and the parameter of my table),
May I know how to code this logic:
1. If Job_code has no pre-requisite, it can now execute the job
2. If Job_ code has pre-requisite/s, the STATUS value of its pre-requisites should be equal to 1 first before it can run
Change
holdfor = catx(',', catt('job '||_job, ' status(', statuses(_job), ')'));
to
holdfor = catx(', ', holdfor, catt('job '||_job, ' status(', statuses(_job), ')'));
in order to 'accumulate' the reasons.
Store each job status in a temporary array as you read the table. Process the prerequisites in a scan loop looking for cases of prior stored job status ne 1. Build up a 'result' that indicates what a job is waiting for is any prerequisites are not 1.
Example:
data have; input Job Status Pre $; datalines; 1 1 . 2 2 . 3 1 . 4 . 1,2,3 5 . 1,4 6 . . ; data want; set have; array statuses(1000) _temporary_; length holdfor $100; statuses(job) = status; if missing(status) then do; do _n_ = 1 to countw(pre); _job = scan(pre,_n_);
* construct a list of holdfor reasons; if statuses(_job) ne 1 then holdfor = catx(', ', holdfor, catt('job '||_job, ' status(', statuses(_job), ')')); end; end; drop _job; run;
Output table
The code presumes another process updates the table 'have' whenever a job changes it's status.
Hello @RichardDeVen . Thank you for assisting.
It seems that there is a little bit of issue here:
if statuses(_job) ne 1 then holdfor = catx(',', catt('job '||_job, ' status(', statuses(_job), ')'));
It only gets the last result. Example:
data have;
input
Job Status Pre $; datalines;
1 . .
2 2 .
3 1 .
4 . 1,2,3
5 . 1,4
6 . .
;
Holdfor column for job=5 should be: job 1 status(.),job 4 status(.). But it will only give job 4 status(.). May I know how to fix this?
Change
holdfor = catx(',', catt('job '||_job, ' status(', statuses(_job), ')'));
to
holdfor = catx(', ', holdfor, catt('job '||_job, ' status(', statuses(_job), ')'));
in order to 'accumulate' the reasons.
Nothing shows up when I try to preview your Excel file. Can you post a jpg instead?
Jim
Hello @jimbarbour . Attached are the details in .doc. Thanks!
Here's what I see on my screen:
In other words, I see nothing but a blank screen.
Would it be possible for you to post a screen capture like the one above that I just posted but showing your data?
Jim
I'm having issue sending pics. But these are the details:
Table:
JOB_CODE Status (1=Execution Done,2=Executing,3=Ready to Execute) Pre_requisite
1 1 .
2 2 .
3 1 .
4 1,2,3
5 1,4
Table Parameters:
Column Name Parameters
Job_Code Numeric
Status Numeric
Pre_Requisite Character
You only have about 20 words of data there. There was no need to first put it into an external file, save the file somewhere, figure out how to upload a file, figure out how to find where you saved the file ...
So just posting it as text to begin with would have saved you and everyone that wants to try to help you a lot of time.
Please post the data as data-step with datalines, so that we don't have to write code brining us in to the point where you are already. Then describe the logic to be applied in full-detail. Right now i don't understand why the variable status has four values: when to set it to 2 or 3? Adding data seems to be a good idea, too, so that all cases exist. To avoid unnecessary coding, switching from excel to a normal text-file is recommended.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.