BookmarkSubscribeRSS Feed

3 Ways to identify a Empty dataset and Obs Count

Started ‎06-16-2014 by
Modified ‎10-05-2015 by
Views 2,174

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;

Version history
Last update:
‎10-05-2015 03:47 PM
Updated by:

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

Register now

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Labels
Article Tags