Help please.
It 's possibile insert a condition in proc export that in case the table to be exported has not a row:
the export must not be.
Thank's
I agree with Art. Here is an example that you may find useful to your scenario:
data have;
set sashelp.class (obs=0);
run;
%macro test;
%let imp_data=have;
/*%let exp_data=;*/
data _null_;
if nobs>0 then call symput("exp_data","&imp_data");
else call symput ("exp_data","");
set &imp_data nobs=nobs;
run;
%if &exp_data ne %then %do;
proc export data=&exp_data
outfile="h:\test.xls"
dbms=excel replace;
run;
%end;
%mend;
%test
you can toggle from obs=0 to obs=10 to test it out. Make sure the outfile destination is valid for your system.
After browsing the paper that Art referred, here comes another version utilizing 'run cancel' method:
%macro test;
data _null_;
if nobs>0 then call symput("rc","");
else call symput ("rc","cancel");
set have nobs=nobs;
run;
proc export data=have
outfile="h:\test.xls"
dbms=excel replace;
run &rc;
%mend;
%test
Regards,
Haikuo
The easiest way I've seen is to insert a macro variable in your code. Take a look at: http://support.sas.com/resources/papers/proceedings11/097-2011.pdf
I agree with Art. Here is an example that you may find useful to your scenario:
data have;
set sashelp.class (obs=0);
run;
%macro test;
%let imp_data=have;
/*%let exp_data=;*/
data _null_;
if nobs>0 then call symput("exp_data","&imp_data");
else call symput ("exp_data","");
set &imp_data nobs=nobs;
run;
%if &exp_data ne %then %do;
proc export data=&exp_data
outfile="h:\test.xls"
dbms=excel replace;
run;
%end;
%mend;
%test
you can toggle from obs=0 to obs=10 to test it out. Make sure the outfile destination is valid for your system.
After browsing the paper that Art referred, here comes another version utilizing 'run cancel' method:
%macro test;
data _null_;
if nobs>0 then call symput("rc","");
else call symput ("rc","cancel");
set have nobs=nobs;
run;
proc export data=have
outfile="h:\test.xls"
dbms=excel replace;
run &rc;
%mend;
%test
Regards,
Haikuo
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.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.