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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 4551 views
  • 0 likes
  • 3 in conversation