BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi i have a code which export many datasets out. However, some of the datasets can be empty sometimes. Is there any command which i can use to export only non-empty data?
5 REPLIES 5
LinusH
Tourmaline | Level 20
I don't know the neatest way in EG to do this, but you can use either DICTIONARY.TABLES or the ATTRN function to find out whether your input table(s) has observations or not, and combine this with some conditional logic using macro programming.

Regards,
Linus
Data never sleeps
deleted_user
Not applicable
use open() and attrn function, you can get the attribution of the table such as variable number , if it is a empty table, the variable number should be 0
andreas_lds
Jade | Level 19
> use open() and attrn function, you can get the
> attribution of the table such as variable number , if
> it is a empty table, the variable number should be 0

The number of variables is not reduced to 0 if a dataset is empty, to find out how many observations are in a dataset use NOBS as second parameter for the attrn function.
deleted_user
Not applicable
Hi,

Thanks so much everyone, I manage to find out the number of observation using the attrn function. However, does anybody knows how to link the following 2 codes together such that it only export data testing if it is non-empty? I tried '%if... then..." but it returns with error message.

1) %let dsid=%sysfunc(open(testing,i));
%let iswhere=%sysfunc(attrn(&dsid,nobs));

2) proc export data=testing
OUTFILE="/SAS/SGH/PFS_CCR/Collection/Risk12/testing&d5.xls"
DBMS=xls REPLACE;
RUN;
LinusH
Tourmaline | Level 20
Somthing like this (untested):

%macro export(table);
%let dsid=%sysfunc(open(testing,i));
%let iswhere=%sysfunc(attrn(&dsid,nobs));
%if &ISWHERE ne 0 %the %do;
proc export data=&TABLE
OUTFILE="/SAS/SGH/PFS_CCR/Collection/Risk12/testing&d5.xls"
DBMS=xls REPLACE;
RUN;
%end;
%mend export;
%export;

/Linus
Data never sleeps

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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