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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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