BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Cello23
Quartz | Level 8

Help please.

It 's possibile insert a condition in proc export that in case the table to be exported has not a row:

no row.jpg

the export must not be.

Thank's

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

View solution in original post

3 REPLIES 3
art297
Opal | Level 21

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

Haikuo
Onyx | Level 15

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

Cello23
Quartz | Level 8

I did.

Thank's a lot Hai.kuo and art297  Smiley Happy

Bye.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2122 views
  • 3 likes
  • 3 in conversation