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;
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:
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:
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.
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
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.
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.