1. I have the following partial character dates how to convert them into numeric date and also compare it with other date
Chardate wantdate year comparedate flag
2019-09 SEP2019 2019 2020-01-20 Y
2018 2018 2020-01-20 Y
2021-08 AUG2021 2021 2020-01-20 N
2021 2021 2020-01-20 N
2. One more request. lhow to perform if chardate< comparedate or year < year( comparedate) incase of month missing then flag=Y else N
Thanks in advance.
Perhaps you could tell us, just in words, if your 5th grade teacher gave you this problem long before you learned to program a computer, what are the methods you would use to figure out if chardate< comparedate.
SAS does not allow partial dates. It must have a year, it must have a month, and it must have a day. So the best thing to do, in my opinion, is if there is no day of the month, assign it to the first day of the month. If there is no month, then assign it to the first day of the year. If you want to do this, you could use this line
numdate = input(cats(chardate,'-01-01'),yymmdd10.);
to create a variable named numdate, which could then be compared to any other date according to my rules above.
To make a date out of a partial string, you must first decide which day and month you want to set as a default. So which day in which month do you want to set when only a year is given, and which day when only year and month are given?
Perhaps you could tell us, just in words, if your 5th grade teacher gave you this problem long before you learned to program a computer, what are the methods you would use to figure out if chardate< comparedate.
SAS does not allow partial dates. It must have a year, it must have a month, and it must have a day. So the best thing to do, in my opinion, is if there is no day of the month, assign it to the first day of the month. If there is no month, then assign it to the first day of the year. If you want to do this, you could use this line
numdate = input(cats(chardate,'-01-01'),yymmdd10.);
to create a variable named numdate, which could then be compared to any other date according to my rules above.
My bad I missed that logic. Thanks for the explanation.
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.