DATA Step, Macro, Functions and more

Problem using %let macro in Proc Export filename

Reply
New Contributor
Posts: 2

Problem using %let macro in Proc Export filename

Hi,

I export a report to Excel daily, with the data in the filename changing each day as follows in an extract of the full code:

%let endDate=20110830;

proc export data=summarylessgst1 outfile='H:\Output\Summary &endDate..xls'

dbms=excel replace;

run;

I had no problem with this when using SAS 9.1, but now I have moved to SAS 9.2, the output does not recognise &endDate., and instead outputs a file named:

'Summary &endDate..xls'

&endDate works fine in the rest of the code, i.e. when only selecting transactions with a date before &endDate. Can anyone help to provide an explanation and/or solution as to why the proc export outfile does not replace &endDate with the specified date?

Thanks

PROC Star
Posts: 7,366

Problem using %let macro in Proc Export filename

I'm surprised that it worked correctly in 9.1.  Enclose your filename in double quotes or else the macro variable won't resolve.  I.e., use:

proc export data=summarylessgst1 outfile="H:\Output\Summary &endDate..xls"

dbms=excel replace;

run;

New Contributor
Posts: 2

Problem using %let macro in Proc Export filename

Thanks art297, I changed to double quotations and it's now reading the macro variable properly. Yes I never thought that would be the issue since single quotations has always worked in SAS 9.1.

Glad it's resolved, thanks again for your help.

Contributor
Posts: 35

Problem using %let macro in Proc Export filename

Oh, really? Even in SAS 9.1, macro variables inside single quotes aren't supposed to be resolved. Are you sure you are remembering correctly?

Valued Guide
Posts: 2,175

Problem using %let macro in Proc Export filename

like with like it's hard to see how it works in 9.1

However, macro variable DATE referenced like '&date'd  (holding a date like 31-Aug-2011)  resolves OK for me, when it is within a longer double-quoted string

Super User
Super User
Posts: 6,502

Problem using %let macro in Proc Export filename

The outer most quotes are the ones that determine if macro references are resolved.

Try:

%let date1=01JAN2011;

%let x1="The date value is '&date1' ";

%let x2='The date value is "&date1" ';

%put x1=%superq(x1);

%put x2=%superq(x2);

Valued Guide
Posts: 2,175

Problem using %let macro in Proc Export filename

yep

it's  all about the outside quoting!

(except.

( unless,

(are you adding something >>>>?

(why use superq?

(in what context does this need superq?

(%put x2=&x2  * demonstrate context 'where "&date1" does not resolve';

(%put x1=&x1  * demonstrate context "where '&date1' does resolve";

(?

Contributor PQK
Contributor
Posts: 21

Problem using %let macro in Proc Export filename

MikeSimmos & art297,

Thanks for posting this question and answer. I was attempting to do a similar operation and could not figure out how to get a macro variable to correctly work with in an ouput filename.

PQK

Ask a Question
Discussion stats
  • 7 replies
  • 7959 views
  • 0 likes
  • 6 in conversation