BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

Hello,

I would like to use the current date to generate an output file.  However, I don't see the output date in my export file name.  I continue getting a '&tdate.' in the end.  Where did I do wrong?  Thanks.

 

data _null_;
	call symput('tdate',put(year("&sysdate"d),4.)||'_'||put(month("&sysdate"d),z2.)||'_'||put(day("&sysdate"d),z2.));
run;

%put &tdate;

ods rtf file = 'Pathwat\AUD1619_RTY_Clinic_&tdate..rtf';

ods rtf close;
1 ACCEPTED SOLUTION

Accepted Solutions
AMSAS
SAS Super FREQ

Macros do not resolve within single quotes see Using Macro Variables 

After a macro variable is created, you typically use the variable by referencing it with an ampersand preceding its name (&variable-name), which is called a macro variable reference. These references perform symbolic substitutions when they resolve to their value. You can use these references anywhere in a SAS program. To resolve a macro variable reference that occurs within a literal string, enclose the string in double quotation marks. Macro variable references that are enclosed in single quotation marks are not resolved. Compare the following statements that assign a value to macro variable DSN and use it in a TITLE statement:

 

 

View solution in original post

4 REPLIES 4
AMSAS
SAS Super FREQ

Macros do not resolve within single quotes see Using Macro Variables 

After a macro variable is created, you typically use the variable by referencing it with an ampersand preceding its name (&variable-name), which is called a macro variable reference. These references perform symbolic substitutions when they resolve to their value. You can use these references anywhere in a SAS program. To resolve a macro variable reference that occurs within a literal string, enclose the string in double quotation marks. Macro variable references that are enclosed in single quotation marks are not resolved. Compare the following statements that assign a value to macro variable DSN and use it in a TITLE statement:

 

 

ErikLund_Jensen
Rhodochrosite | Level 12

Hi @ybz12003 

 

It is not working because the rtf filename is in single quotes. Then the macro variable reference is treated as a constant.

Use double quotes instead.

andreas_lds
Jade | Level 19

You can simplify the creation of the date variable by using put with format yymmddn8:

30         data _null_;
31            call symputx('tdate', put("&sysdate."d, yymmddn8.));
32         run;
33         
34         %put &=tdate;
TDATE=20220913
PaigeMiller
Diamond | Level 26

Great point from @andreas_lds . To @ybz12003 you should never need to pull apart text strings to work with SAS dates; there are plenty of built-in functions/formats/informats that you can use to avoid the need to pull apart text strings. SAS has done the hard work regarding handling dates, so you don't have to.

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 577 views
  • 2 likes
  • 5 in conversation