- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 !
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Next up: SAS Trivia Quiz hosted by SAS on Wednesday May 21.
Register now at https://www.basug.org/events.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Next up: SAS Trivia Quiz hosted by SAS on Wednesday May 21.
Register now at https://www.basug.org/events.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;