BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASuserlot
Barite | Level 11

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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?

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
SASuserlot
Barite | Level 11

 My bad I missed that logic. Thanks for the explanation.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1142 views
  • 3 likes
  • 3 in conversation