For the life of me I cannot remember how to do this.
I have the following %let statement(s), which work beautifully when setting them in my where statements:
*CURRENT DATE*/
%LET CD=INTNX('DAY',TODAY(),-1);
/*CURRENT MONTH START DATE*/
%LET CM=INTNX('MONTH',INTNX('MONTH',TODAY(),1),-1);
/*CURRENT YEAR START DATE*/
%LET CY=INTNX('YEAR',INTNX('YEAR',&CD,1),-1);
However, I cannot remember how in the world to validate the dates (results shown in the log) with the %put statement. Any one out there have any ideas?
Thanks!
Erm, thats obfuscation. We have a function called today() which everyone knows, and you are wrapping that into macro variables, why? You can just use the function directly in code, for example this:
%LET CD=INTNX('DAY',TODAY(),-1); data want; set have; where date=&cd.; run;
Is the same (but harder to debug) as:
data want; set have; where date=today()-1; run;
As for putting that information into the log, you first need to actually run the code held in the macro varaibles, as they are just text, so maybe something like:
data _null_; format cd cm cy date9.; cd=&cd.; cm=&cm.; cy=&cy.; put _all_; run;
Erm, thats obfuscation. We have a function called today() which everyone knows, and you are wrapping that into macro variables, why? You can just use the function directly in code, for example this:
%LET CD=INTNX('DAY',TODAY(),-1); data want; set have; where date=&cd.; run;
Is the same (but harder to debug) as:
data want; set have; where date=today()-1; run;
As for putting that information into the log, you first need to actually run the code held in the macro varaibles, as they are just text, so maybe something like:
data _null_; format cd cm cy date9.; cd=&cd.; cm=&cm.; cy=&cy.; put _all_; run;
You are just assigning the CODE to calculate dates to the macro variables. You are not actually telling SAS to execute that code.
If you want to execute functions in macro code then you need to use the %SYSFUNC() macro function.
%LET CD=%sysfunc(INTNX(DAY,%sysfunc(TODAY()),-1));
This will set CD to the number of days since 01JAn1960. That is fine for using in SAS code, but would be diffucult for a human to translate. You could use the option second argument to %SYSFUNC() to have SAS format the result to look like a date.
%LET CD=%sysfunc(INTNX(DAY,%sysfunc(TODAY()),-1),date9);
But then to use it in SAS code you will need to let SAS itself know that you meant that stream of characters to represent a date. For example by using it as a date literal.
duration = "&cd"d - start_dt ;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.