DATA Step, Macro, Functions and more

Export table only when it contains data

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Export table only when it contains data

[ Edited ]

Good Afternoon!

 

I have the below exporting query, but I only want the table to export if it contains observations. 

 

PROC EXPORT DATA=results.ClosingStockWave1 DBMS=csv
OUTFILE="\\athena\Projects\Tanzania PMI RA\Data Management\SAS Setup\Field Queries\NewSKUs.csv" REPLACE;
RUN;

 

Can anyone assist me?

 

Kind Regards


Accepted Solutions
Solution
‎09-14-2016 05:48 AM
Super User
Posts: 19,837

All Replies
Solution
‎09-14-2016 05:48 AM
Super User
Posts: 19,837

Re: Export table only when it contains data

Posted in reply to GonetteSmith
Super User
Posts: 10,041

Re: Export table only when it contains data

Posted in reply to GonetteSmith
Make a macro:



%macro export(dsn=);
%let dsid=%sysfunc(open(&dsn));
%let nobs=%sysfunc(attrn(&dsid,nlobs));
%let dsid=%sysfunc(close(&dsid));

%if &nobs ne 0 %then %do;
 %put Put your EXPORT here;
%end;
%mend;


%export(dsn=sashelp.class)


☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 209 views
  • 1 like
  • 3 in conversation