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';
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.