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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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