Hi Expert,
I want to display total records available for particular dataset in the email template. If not available, it should display zero. Can you please help me. I tried with macro but it is not displaying.
data class; set sashelp.class; run; data school; input stud_id; cards; ; run; FILENAME myemail2 EMAIL to=("abc@yahoo.com" ) Subject = "count check"; data _null_; file myemail2; Put "Total number of records in dataset class=" & 19; Put "Total number of records in dataset school=" & 0; run;
Using the original code, add a check for the automatic variable &sysnobs (which captures the number of obs processed in that data step). I tweaked the subject so you can also see the counts in the subject without opening the message:
data class;
set sashelp.class;
run;
%let obs_class=&sysnobs;
data school;
input stud_id;
cards;
;
run;
%let obs_school=&sysnobs;
FILENAME myemail2 EMAIL to=("abc@yahoo.com" )
Subject = "count check: class=&obs_class school=&obs_school";
data _null_;
file myemail2;
Put "Total number of records in dataset class=&obs_class";
Put "Total number of records in dataset school=&obs_school";
run;
Can you show how yout tried, with macros?
I would expect the sample code you posted to throw an error, caused by the & outside of the quoted text. But if you put the counts inside the quotes it should work fine, e.g.:
9 data _null_; 10 Put "Total number of records in dataset class=19"; 11 Put "Total number of records in dataset school=0"; 12 run; Total number of records in dataset class=19 Total number of records in dataset school=0
So you have the emailing part working like you want?
If so, then I would probably use a function-style macro that returns a count of the number of records in a dataset, see e.g. http://www2.sas.com/proceedings/sugi26/p095-26.pdf .
With that, you should be able to get what you want with something like:
data _null_ ; file myemail2 ; put "Total number of records in dataset class= %countobs(class)" ; put "Total number of records in dataset school=%countobs(school)" ; run ;
Thanks for the information.
I use the suggested code but the email body do not resolve the code. It displays like below
Total number of records in dataset class= %countobs(class) Total number of records in dataset school=%countobs(school)
Did you define a macro named %countobs() before you ran that code? That is the first step. The paper I linked to has an example. You need to compile the macro first.
Using the original code, add a check for the automatic variable &sysnobs (which captures the number of obs processed in that data step). I tweaked the subject so you can also see the counts in the subject without opening the message:
data class;
set sashelp.class;
run;
%let obs_class=&sysnobs;
data school;
input stud_id;
cards;
;
run;
%let obs_school=&sysnobs;
FILENAME myemail2 EMAIL to=("abc@yahoo.com" )
Subject = "count check: class=&obs_class school=&obs_school";
data _null_;
file myemail2;
Put "Total number of records in dataset class=&obs_class";
Put "Total number of records in dataset school=&obs_school";
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.