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

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
  • 7 replies
  • 13367 views
  • 0 likes
  • 6 in conversation