BookmarkSubscribeRSS Feed
Aidan
Quartz | Level 8

I have a job that will check if a certain date exists in a data set.

 

If it does I want the next few nodes of the job to execute, if not I want the job to stop completely.

 

How can this be done?

 

Thanks

Aidan

8 REPLIES 8
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Ca you use SAS code?  If so:
%if %sysfunc(fileexists(...)) %then %do;

...

 

Or sort data nodupkey to create a dataset, then check sashelp.vtable:
data _null_;

  set sashelp.vtable (where=(libname="<libname>" and memname="<dataset>" and nobs > 0));

  call execute('%include <next job>';);

run;

 

Will only call the execute if more than 0 obs.

LinusH
Tourmaline | Level 20

@RW9 example would certainly work programming wise, but it's not really DI Studio best practice...

You could use the same logic with an Extract, and have that as output to a Loop. No entries in the look up table, no loops.

Another option is to use post cade in the extract, if the result table is empty, execute endsas/abort abend etc.

Third option is try to use the Conditional Start/End transformations.

Data never sleeps
Aidan
Quartz | Level 8

I have tried a conditional start and end as per attached however it seems to just stop on conditional start

Kurt_Bremser
Super User

Just for reference, Aidan has asked related questions in

https://communities.sas.com/t5/SAS-Studio/Conditional-Start/m-p/339634

and

https://communities.sas.com/t5/SAS-Data-Management/Conditional-Start-amp-End/m-p/340000

 

Personally, I would dissect the job into its parts and have the scheduler handle the continuation conditions, controlled by return codes from the single jobs, or by the execution date as such.

Aidan
Quartz | Level 8
@Kurt_Bremser I needed some more direction so had to post a new thread as it could be that I am approaching this incorrectly. Very new to writing on the fly SAS code so need more direction on this,
Kurt_Bremser
Super User

@Aidan wrote:
@Kurt_Bremser I needed some more direction so had to post a new thread as it could be that I am approaching this incorrectly. Very new to writing on the fly SAS code so need more direction on this,

No problem. I just wanted to give everybody new to the topic a chance to see what was already talked about. Otherwise I'd have merged the threads into one, but I see an evolution of the theme(s) 😉

Aidan
Quartz | Level 8

I have pre code in an extract node to check if data set is blank;

data _null_;
dsid = open("&_Input");
call symputx('NOBS',attrn(dsid,'NOBS');
run;

 

I will only then e-mail the results if the data set is not blank as per below;

PROC EXPORT DATA=work.W4JQ299
OUTFILE="\\test\my file.csv"
DBMS=CSV Replace;
PUTNAMES=YES;
RUN;

%macro email;
%if &NOBS <> 0 %then %do;
data _null_;
file sendit email
from="from"
to=("to")

subject="test"
attach=("\\test\my file.csv");
put "Hi all,";
put;
put "xxxxxxxxxxxxxx";
put;
put "Kind Regards,";
put "Aidan";
run;

%end;
%mend email;
%email;

 

The email code doenst seem to be working, any ideas?

I have removed the e-mail address and file location for security on here

 

Thanks

Aidan 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 8 replies
  • 2114 views
  • 0 likes
  • 4 in conversation