Desktop productivity for business analysts and programmers

Export data only when the data is not empty

Reply
N/A
Posts: 0

Export data only when the data is not empty

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?
Esteemed Advisor
Posts: 5,194

Re: Export data only when the data is not empty

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
N/A
Posts: 0

Re: Export data only when the data is not empty

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
Regular Contributor
Posts: 234

Re: Export data only when the data is not empty

> 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.
N/A
Posts: 0

Re: Export data only when the data is not empty

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;
Esteemed Advisor
Posts: 5,194

Re: Export data only when the data is not empty

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