BookmarkSubscribeRSS Feed
Aidan
Quartz | Level 8

Hi there,

 

What I want to do is run a job based on the date of the month which can vary.

So I was thinking of using conditional start.

 

If I had a table with a list of dates, and that date matched "&sysdate"d - 1 I would want the job to run, but if not stop the job and dont process the job.

 

Has anyone any ideas on how to achieve this, I have looked for examples but am struggling on it.

 

Thanks,

Aidan 

13 REPLIES 13
Aidan
Quartz | Level 8

I would have 1 data set with multiple different dates and then if a date within that data set matches today-1, i will run  ajob, if not, do nothing

Kurt_Bremser
Super User

@Aidan wrote:

I would have 1 data set with multiple different dates and then if a date within that data set matches today-1, i will run  ajob, if not, do nothing


Ok, so I suggest:

%macro run_job_cond;

%let flag=no;

data _null_;
set have;
if date = today() - 1 then call symput('flag','yes');
run;

%if &flag=yes
%then %do;
/* run the job here */
%end;

%mend;

%run_job_cond

How you run the job depends on what the "job" is. If it is a SAS code suitable for %include, then you could do that. If it is something that should be run in a clean batch job, use one of the methods to call external commands and use SAS from the commandline.

Astounding
PROC Star

Here's one way to proceed.  Take the job you might want to run, and add this to the beginning of it.  Assuming you have your list of dates stored in a SAS data set with one date value per observation:

 

data _null_;

call symputx('date_found', 'endsas;');

set list_of_dates;

if date = "&sysdate9"d - 1 then do;

   call symputx('date_found', ' ');

   stop;

end;

run;

 

&date_found

 

When there is no matching date, &DATE_FOUND generates ENDSAS; and the program stops.  Just run the program every day.

 

There are other non-SAS approaches that use job schedulers, depending on your operating system.  But this would be an easy SAS-based approach.

 

 

Aidan
Quartz | Level 8

Thank you both, I have both implemented so hopefully it will work ,  I will know on the 20th so will accpet solution for whichever works.

 

Thanks again for the quick reply 

 

 

Aidan
Quartz | Level 8

If in node 1 the dates match, will it progress onto node 2 as per attachment?

See code in node 1 below

 

data _null_;
call symputx('date_found', 'endsas;');
set &_INPUT1;
if date = "&sysdate9"d - 1 then do;
call symputx('date_found', ' ');
stop;
end;
run;

&date_found

Kurt_Bremser
Super User

I guess you're mixing things here. If you work with a process flow, you should use the controls available in process flows. So I'd add a node that checks your dataset and sets a macro variable, which you can then use in conditions in your process flow.

What @Astounding and I have given you are options to use with stand-alone SAS code.

You could try to wrap my solution around the code of your nodes, but you would lose the process-flow functionality on the way, as you'll end up with a single monolithic piece of code.

The endsas statement @Astounding uses immediately terminates the SAS workspace server session, so EG would have to start a new workspace server to continue (which would lose all macro variables etc)

Aidan
Quartz | Level 8

startement the next node has code like the below;

proc sql;
create view work.W2LB59M as
select
(datepart(BILLING_RUN_DT)) as BILLING_RUN_DT length = 8
format = date11.
informat = DATETIME20.
label = 'BILLING_RUN_DT'
from &SYSLAST
where "&Sysdate"d-1>=datepart(BILLING_RUN_DT)
;
quit;

%let SYSLAST = work.W2LB59M;

 

 

 

So I need to put that here as highlitged with "CODE TO PROCESS"

 

 

data _null_;
call symputx('date_found', 'endsas;');
set &_INPUT1;
if date = "&sysdate9"d - 1 then do  "CODE TO PROCESS";
call symputx('date_found', ' ');
stop;
end;
run;

&date_found

Aidan
Quartz | Level 8

Yeah I use DI more often than not, but have used some user written in the past

Kurt_Bremser
Super User

Since I do not work with DI Studio, you need to take my suggestions from now on with a grain of salt.

If DI Studio works like EG, you can set conditions for each node in the flow. One of the options (in EG, mind) for such a condition is to query the value of a macro variable.

If you now enter the data step code that checks the control dataset into a node at the beginning like this:

%let continue=no;
data _null_;
set control;
if date = today() - 2
then do;
  call symput('continue','yes');
  stop;
end;
run;

You can then add a condition on the following nodes that queries for &continue=yes.

Aidan
Quartz | Level 8

Ok this is where I am at now.

 

I have a table with the last run date on its own, being the 15th of Feb 2017.

 

This is node 1.

Node 2 contains the following, so I want to run a test if the criteria matches which is should.

 


%let continue=no;
data temp1;
set &_INPUT1;
if BILLING_RUN_DT = '15Feb2017'd
then do;
call symput('continue','yes');
stop;
end;
run;

 

Then node 3 does the processing of the rest of the DI job which has a where clause of &continue=yes

 

This still doens't seem to be executing from node 3 with any data even though I have data that matches to the 15th of Feb so the condition should be yes.

 

Has anyone any ideas at this point?

 

Thanks

Aidan 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 13 replies
  • 2280 views
  • 3 likes
  • 3 in conversation