Hi,
I want to add to the filename the date of today. I tried the code below but it does'nt work.
How can I use my variable pathname in the filename syntax?
data _NULL_; StringA = '/project/XXXXX/out/XX_EXPORT_'; StringM = %sysfunc(today(), YYMMYYN6.); StringE = '.csv'; %LET pathname = cats(StringA, StringM, StringE); put pathname; run; filename OUTPUT &pathname encoding='utf-8'; proc export data=XXXXXX.XX_NG outfile=OUTPUT dbms=csv; run;
Thanks,
Sascha
Macro timing mistake. The %LET is dealt with while the data step is compiled, not while it executes.
Use the proper data step function for setting a macro variable:
data _NULL_;
StringA = '/project/XXXXX/out/XX_EXPORT_';
StringM = put(today(),YYMMYYN6.);
StringE = '.csv';
call symputx('pathname',cats(StringA, StringM, StringE));
run;
But you can do this in one %LET:
%let pathname =/project/XXXXX/out/XX_EXPORT_%sysfunc(today(),YYMMYYN6.).csv;
And since the macro variable &pathname does not contain quotes, add them when it is used:
filename OUTPUT "&pathname" encoding='utf-8';
Macro timing mistake. The %LET is dealt with while the data step is compiled, not while it executes.
Use the proper data step function for setting a macro variable:
data _NULL_;
StringA = '/project/XXXXX/out/XX_EXPORT_';
StringM = put(today(),YYMMYYN6.);
StringE = '.csv';
call symputx('pathname',cats(StringA, StringM, StringE));
run;
But you can do this in one %LET:
%let pathname =/project/XXXXX/out/XX_EXPORT_%sysfunc(today(),YYMMYYN6.).csv;
And since the macro variable &pathname does not contain quotes, add them when it is used:
filename OUTPUT "&pathname" encoding='utf-8';
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.