DATA Step, Macro, Functions and more

Proc exprt (condition)

Accepted Solution Solved
Reply
Contributor
Posts: 51
Accepted Solution

Proc exprt (condition)

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


Accepted Solutions
Solution
‎02-07-2012 08:44 AM
Respected Advisor
Posts: 3,124

Re: Proc exprt (condition)

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


All Replies
PROC Star
Posts: 7,356

Proc exprt (condition)

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

Solution
‎02-07-2012 08:44 AM
Respected Advisor
Posts: 3,124

Re: Proc exprt (condition)

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

Contributor
Posts: 51

Proc exprt (condition)

I did.

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

Bye.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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