BookmarkSubscribeRSS Feed
tparvaiz
Obsidian | Level 7

Hi,

 

We send out reports via email. we have one project for each report and each report is sent out individually to multiple recipients

 

usually we run the sas code that generates an output in excel and then we manually send our emails and make attachments. The reason we do it is to ensure that we are not sending out garbage files (incase data is missing)

 

is there a way we can automate this process (with some sanity check, something like do a count of records and if the count is in between a defined range for the given report then send it out otherwise generate an error email to notify whoever looks after that report)?

 

Please assist

 

Thanks, in advance

1 REPLY 1
ArtC
Rhodochrosite | Level 12

Assuming that your check will be against the observation count in a data set, here is a little macro that i use to return the number of observations in a data set.

%macro obscnt(dsn); 
%local nobs dsnid rc;
%let nobs=.;

%* Open the data set of interest;
%let dsnid = %sysfunc(open(&dsn)); 

%* If the open was successful get the;
%* number of observations and CLOSE &dsn;
%if &dsnid %then %do; 
     %let nobs=%sysfunc(attrn(&dsnid,nlobs));
     %let rc  =%sysfunc(close(&dsnid)); 
%end;
%else %do; 
     %put WARNING: Unable to open &dsn;
     %put %sysfunc(sysmsg());
%end;

%* Return the number of observations;
&nobs 
%mend obscnt;

in your program you might use it something like:

%if %obscnt(mydata)>25 %then %do;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 936 views
  • 0 likes
  • 2 in conversation