BookmarkSubscribeRSS Feed
Scottcom4
Calcite | Level 5
Hi all,

I have been trawling the internet trying to work out the appropriate function, so I am hoping that someone can assist.

What I want to do is send an email only when the dataset has an observation (or more than one). I have set up a Macro which sends the email, however am having trouble allocating a variable which can be resolved.

I am using the below code and the marcro at the bottom of my code will run where appropriate. The problem is that when the dataset is empty EMAILREQ will not resolve to N.

Does anyone have any ideas??

data _NULL_;
set agedebt_unknowns;
if _N_ >= 1 then CALL SYMPUT("EmailReq",'Y');
else CALL SYMPUT("EmailReq",'N');
Run;

Thanks for your help.
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Investigate using the NOBS= keyword on the SET statement. And you must move your IF statement to be located before the SET, but only if you want to do the CALL SYMPUT within the DATA step. Another option is a %LET statement before the DATA step - must either be outside of a %MACRO/%MEND or declare a %GLOBAL variable. Lastly, if you only need to set the macro variable, there is a SAS macro language technique to open a SAS file, to get the observations count. Have a look at the %SYSFUNC invocation and using the SAS Data step functions to open and get info about a SAS file.

Scott Barry
SBBWorks, Inc.
Scottcom4
Calcite | Level 5
Hi SBB,

Thank you for your reply.

Regards,
Scottcom4 Message was edited by: Scottcom4
yonib
SAS Employee
Hi,
I think this example might be usefull for you:


%let num=0;
data _null_;
input x;
call symput('num',_n_);/*counting the numbers of rows in your dataset
cards;
1
2
3
4
5
6
7
8
;
run;
%put #
%macro check_num;
%if &num>0 %then %do;
filename mymail email "yonib@bbb.com"
from="yonib@bbb.com "
subject="the data set has &num obs";
data _null_;
file mymail;
put 'free text';
run;
%end;
%else %do ;
filename mymail email "yonib@bbb.com"
from="yonib@bbb.com "
subject="the data set has no obs";
data _null_;
file mymail;
put 'free text';
run;
%end;
%mend;
%check_num;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 735 views
  • 0 likes
  • 3 in conversation