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
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.