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: 17,828

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

Re: Export table only when it contains data

Super User
Posts: 9,681

Re: Export table only when it contains data

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
  • 205 views
  • 1 like
  • 3 in conversation