Hello Experts,
I'm wondering why this data comparing doesn't work (I have also the date> 01/04/2024 in base finale)
data base_finale;
set base2;
if month("Date de réception"n)<="01APR2024"d;
run;
The format of coulmn is "Date de réception"n
Thank you !
When you say "doesn't work" I assume you mean the code runs without errors or warnings in the log, but you're surprised by the result?
What is your intent for this code?
If you want to select records with date on or before the April 1, 2024, don't use the MONTH function, try:
if "Date de réception"n <= "01APR2024"d ;
The MONTH() function will return 1-12, which is probably not what you want. When you use the MONTH function, this comparison will always be true.
When you say "doesn't work" I assume you mean the code runs without errors or warnings in the log, but you're surprised by the result?
What is your intent for this code?
If you want to select records with date on or before the April 1, 2024, don't use the MONTH function, try:
if "Date de réception"n <= "01APR2024"d ;
The MONTH() function will return 1-12, which is probably not what you want. When you use the MONTH function, this comparison will always be true.
The MONTH function will return a value of 1 to 12 when given a numeric (hopefully date) value or missing if the argument is missing. So you get a return of at most 12. The date 01APR2024 has a numeric value of 23467.
So any result from the Month function will be much less than 23467.
If you haven't encountered it before, missing is always less than any non-missing value.
Are you looking for any row where the comparison date is from the same or previous month, or should the two dates only be max one month apart? Below code should give you an idea of the options.
data base2;
format "Date de réception"n ddmmyy10.;
"Date de réception"n='20mar2024'd; output;
"Date de réception"n='20may2024'd; output;
"Date de réception"n='12jan2023'd; output;
run;
run;
data base_finale;
set base2;
/* if intck('month',"Date de réception"n,"01APR2024"d) in (0,1); */
interval_1=intck('month',"Date de réception"n,"01APR2024"d);
interval_2=intck('month',"Date de réception"n,"01APR2024"d,'c');
run;
proc print data=base_finale;
run;
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.