BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
iSAS
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
RichardDeVen
Barite | Level 11

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.

View solution in original post

10 REPLIES 10
RichardDeVen
Barite | Level 11

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

RichardADeVenezia_0-1599058072000.png

 

The code presumes another process updates the table 'have' whenever a job changes it's status.

iSAS
Quartz | Level 8

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?

RichardDeVen
Barite | Level 11

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.

jimbarbour
Meteorite | Level 14

Nothing shows up when I try to preview your Excel file.  Can you post a jpg instead?

 

Jim

iSAS
Quartz | Level 8

Hello @jimbarbour . Attached are the details in .doc. Thanks!

jimbarbour
Meteorite | Level 14

Here's what I see on my screen:  Screen_Shot_iSAS_2020-09-02_09-06-30.jpg

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

iSAS
Quartz | Level 8

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

Tom
Super User Tom
Super User

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.  

iSAS
Quartz | Level 8
Thank you for bringing this up. It will help everyone know how good you are in checking errors. Now that it is posted in text, would you still like to help?
andreas_lds
Jade | Level 19

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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 1357 views
  • 0 likes
  • 5 in conversation