BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SaschaD
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

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

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore 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
  • 1 reply
  • 1448 views
  • 0 likes
  • 2 in conversation