BookmarkSubscribeRSS Feed
MikeSimmos
Calcite | Level 5

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

7 REPLIES 7
art297
Opal | Level 21

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;

MikeSimmos
Calcite | Level 5

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.

DouglasMartin
Calcite | Level 5

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?

Peter_C
Rhodochrosite | Level 12

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

Tom
Super User Tom
Super User

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);

Peter_C
Rhodochrosite | Level 12

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";

(?

PQK
Calcite | Level 5 PQK
Calcite | Level 5

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 7 replies
  • 14467 views
  • 0 likes
  • 6 in conversation