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
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;
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.
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?
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
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);
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";
(?
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.