Help using Base SAS procedures

Empty Datasets

Reply
Contributor
Posts: 42

Empty Datasets

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.
Super Contributor
Super Contributor
Posts: 3,174

Re: Empty Datasets

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.
Contributor
Posts: 42

Re: Empty Datasets

Hi SBB,

Thank you for your reply.

Regards,
Scottcom4 Message was edited by: Scottcom4
SAS Employee
Posts: 105

Re: Empty Datasets

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;
Ask a Question
Discussion stats
  • 3 replies
  • 127 views
  • 0 likes
  • 3 in conversation