Hi guys, I am trying to match a macro variable called & today
that contains a date that it extracts from a variable suppose it contains
then I create the macro variable from today which contains the date in date9 format.
I have tried to change each of the dates to be either date9 format.
or datetime16 format, but when I do the% put to see what is inside it only comes out ******
I have tried subtring to transform from ddmmyy but it doesn't work either
y too
The value you have the variable HOY is a datetime value (or more accurate the string of characters the DATETIME format would generate for that datetime value) which is a number of seconds. A better name for the variable might be AHORA.
The value you are putting into TODAYSDATE is a date value (number of days).
So to compare them you will need to convert them. Both convert them to the same type of values (days or seconds) but also convert the representations to be the same style (string that represents the raw number or a string that is formatted for human understanding).
Since you want to compare to a date you probably want to convert your number of seconds to the number of days and then compare. Then INPUTN() function can convert a string into a number. The proper informat to use with that string is the DATE9 informat as it will convert the first 9 characters in &HOY into a date value.
%if %sysfunc(inputn(&hoy,date9.)) = &todaysdate %then ...
Another method is to use the fact that the date literals ignore any time component. So SAS code would treat "&hoy"d as a date value and ignore the :00:00 . But to use date literals in macro code you need to explicitly use the %SYSEVALF() function instead of the implied %EVAL() function.
%if %sysevalf( "&hoy"d = &todaysdate ) %then ...
First thing: MACRO language is basically text. If you have values that are actually numeric, like the result of the today() function you are causing extra work by formatting them.
Second, your &hoy value is displaying the characteristics of a DATETIME value, not a date which is critical for comparison.
Where is &hoy created? If you want to compare to a date why is there a time component?
To have something close to comparison you want have to either create a date value for &hoy to compare with the result of Today() or create a datetime to compare possibly:
%let td =%sysfunc(putn(%sysfunc(dhms(%sysfunc(today()),0,0,0)), datetime18.)); %put &td.;
Note: I frequently observe lazy programming resulting in date values stored as datetimes from some sources. If there is NO time component ever supplied, as in all the times are 00:00:00 then the value should not bother with the time component.
Note: There is a "feature" of the DATETIME format that makes the width of 18 not work as expected. 18 characters should be enough room for 9 character date a separator and 8 character time but SAS will use only 7 character date. Use a width of at least 19 with datetime to get four digit years.
1277 data _null_; 1278 ahora = datetime(); 1279 put ahora / ahora datetime18. / ahora datetime19. ; 1280 run; 1931080325.2 11MAR21:11:12:05 11MAR2021:11:12:05
The value you have the variable HOY is a datetime value (or more accurate the string of characters the DATETIME format would generate for that datetime value) which is a number of seconds. A better name for the variable might be AHORA.
The value you are putting into TODAYSDATE is a date value (number of days).
So to compare them you will need to convert them. Both convert them to the same type of values (days or seconds) but also convert the representations to be the same style (string that represents the raw number or a string that is formatted for human understanding).
Since you want to compare to a date you probably want to convert your number of seconds to the number of days and then compare. Then INPUTN() function can convert a string into a number. The proper informat to use with that string is the DATE9 informat as it will convert the first 9 characters in &HOY into a date value.
%if %sysfunc(inputn(&hoy,date9.)) = &todaysdate %then ...
Another method is to use the fact that the date literals ignore any time component. So SAS code would treat "&hoy"d as a date value and ignore the :00:00 . But to use date literals in macro code you need to explicitly use the %SYSEVALF() function instead of the implied %EVAL() function.
%if %sysevalf( "&hoy"d = &todaysdate ) %then ...
MUCHAS GRACIAS , ME SIRVIO , THANKS I LOVE YOU
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.