That will work.
The question to ask is whether once the macro processor has finished converting the text do you have valid SAS syntax. You can test it be replacing the macro variable reference with the text the macro variable contains. (You should do this in your head as you are writing SAS code that uses macro variable references.)
There are style choices involved.
Your code should work after you fix the curly quotes in your %let statement, with a simple example like this.
%let mydate=‘01jan2021’d;
You must use simple ' quote marks.
I, again I will say as a style choice, dislike quotes in macro variables I create with %Let for dates and would use in this case:
%let mydate=01jan2021; data test1; set test ; If dt= "&mydate."d; Run;
Using the date literal version in the IF statement makes it clear that the intended value that MYDATE should contain is a date literal. So debugging may be easier. Plus I could then use Mydate in something like a title statement: Title "This report was generated for &mydate.";
or labels for a variable : label thisvar = "Measured as of &mydate.";
or in a filename: ods rtf file="<path>/reportfile &mydate..rtf";
Hi nickspencer,
You can also use the following code to generate SAS internal date value:
%let mydate = %sysfunc(inputn(01jan2021,date9.));
The value of &mydate will be an internal SAS date value 22281 (equal to the number of days from 01jan1960).
Then you can refer to it in your code as &mydate without quotes and letter d at the end.
Hope this helps.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.