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??
if _N_ >= 1 then CALL SYMPUT("EmailReq",'Y');
else CALL SYMPUT("EmailReq",'N');
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.