We’re smarter together. Learn from this collection of community knowledge and add your expertise.

3 Ways to identify a Empty dataset and Obs Count

by Regular Learner Anind_Sharma on ‎06-16-2014 03:41 AM - edited on ‎10-05-2015 03:47 PM by Community Manager (246 Views)

1st Way:-

 

%macro test;

 

%local InDat Exist NumObs;

%let InDat = MM_IP;

%let Exist = No;

%let NumObs = 0;

 

DATA null;

set sashelp.vmember(where = (libname = "WORK" and memtype = "DATA"));

if upcase(memname) = "%upcase(Retail_summ1)" then call symput("Exist",'Yes');

RUN;

 

%if &Exist = Yes %then %do;

%let DSNId = %sysfunc(open(Retail_summ1));

%let DSObs = %sysfunc(attrn(&DSNId.,nobs));

%let rc = %sysfunc(close(&DSNId.));

%let NumObs = &DSObs ; %end;

 

2nd Way:-

%let Exist = No;

%let NumObs = 0;

%if %sysfunc(exist(&InDat)) %then %let Exist = Yes;

%if &Exist = Yes %then %do;

PROC SQL noprint;

select * from &InDat;

QUIT;

%let NumObs = &SQLObs;

%end;

 

3rd Way:-

%put EXIST: &Exist;

%put NUMBER OF OBS: &NumObs;

%if &Exist = No or &NumObs = 0 %then %do;

     DATA pval; prob = .;

     RUN;

%end;

 

%mend;

 

%put &NumObs &Exist;

Your turn
Sign In!

Want to write an article? Sign in with your profile.


Looking for the Ask the Expert series? Find it in its new home: communities.sas.com/askexpert.