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

Working in DI Studio, I have three objects: a SAS Data Set, a List Data transformation for creating a report, and a User Written transformation for sending out emails with the report as an attachment.

If there aren't any rows in the SAS Data Set, I don't want the job to send out an email (the users have no need of being sent an empty report). How do I accomplish this? I assume I need to write something in the precode or code of the User Written transformation.

Thanks for your attention.

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20

precode list:

data _null_;

     dsid = open("&_Input");

     call symputx('NOBS',attrn(dsid,'NOBS');

run;

uaser written:

%macro email;    

%if &NOBS <> 0 %then %do;

          your mail code...

%end;

%mend email;

%email;

Data never sleeps

View solution in original post

5 REPLIES 5
LinusH
Tourmaline | Level 20

In the precode to the list transform, you could have code to check no of observation in the input table, if 0, issue an endsas statement (or abort if you need an rc out from the job).

Data never sleeps
TurnTheBacon
Fluorite | Level 6

Thanks Linus.

Can someone please give me an idea of what that code might look like though? I'm still not very experienced in writing customized code.

P.S. The entire job shouldn't be terminated, only the part of the job flow that runs through the table without any rows in it. The three objects I described above are parts of a greater job.

LinusH
Tourmaline | Level 20

There are some SAS functions that can read metadata about a table, and attrn() will give you no of obs.

The function can be called from a data step or a macro by wrap it in %sysfunc().

If you don't want to terminate the session (meaning you'll have other steps, other than the e-mail sending, afterwards you wish to complete), you code could create a macro variable, which you could analyze in the e-mail step.

Data never sleeps
TurnTheBacon
Fluorite | Level 6

Thanks again for the advice. As I said I really have no idea how to write it out in the precode though, still being new to this, and new to macros in particular. I'd greatly appreciate an example of what it might look like, if anyone have the time. Then I should be able to modify it to suit my job.

LinusH
Tourmaline | Level 20

precode list:

data _null_;

     dsid = open("&_Input");

     call symputx('NOBS',attrn(dsid,'NOBS');

run;

uaser written:

%macro email;    

%if &NOBS <> 0 %then %do;

          your mail code...

%end;

%mend email;

%email;

Data never sleeps

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!

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
  • 5 replies
  • 1654 views
  • 6 likes
  • 2 in conversation