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

I have dates that are messy. The missing values are coded as 99 for month and year. 

The rule i want to implement is as follows:

Month missing/day missing/Year = 7/1/Year

Month/day missing/Year = Month/15/Year

Here is the dataset:

DateR
99/99/2006
99/99/2006
8/99/2017
8/99/2017
8/99/2017
8/99/2017
7/99/2018
7/99/2018
6/99/2015

 Thanks!!

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Do you have any with just Month missing (assume by "missing" you mean a value of 99 is recorded and that the expected order is MMDDYYYY)?

 

And including one actual valid date for comparison:

data example;
   input DateR :$10.;
   if scan(dater,2)='99' then do;
      if scan(dater,1)='99' then date=mdy(7,1,input(scan(dater,3),best.));
      else date= mdy(input(scan(dater,1),best.),15,input(scan(dater,3),best.));
   end;
   else date= input(dater,mmddyy10.);
   format date mmddyy10.;
datalines;
99/99/2006
99/99/2006
8/99/2017
8/99/2017
8/99/2017
8/99/2017
7/99/2018
7/99/2018
6/99/2015
4/12/2012
;

View solution in original post

3 REPLIES 3
ballardw
Super User

Do you have any with just Month missing (assume by "missing" you mean a value of 99 is recorded and that the expected order is MMDDYYYY)?

 

And including one actual valid date for comparison:

data example;
   input DateR :$10.;
   if scan(dater,2)='99' then do;
      if scan(dater,1)='99' then date=mdy(7,1,input(scan(dater,3),best.));
      else date= mdy(input(scan(dater,1),best.),15,input(scan(dater,3),best.));
   end;
   else date= input(dater,mmddyy10.);
   format date mmddyy10.;
datalines;
99/99/2006
99/99/2006
8/99/2017
8/99/2017
8/99/2017
8/99/2017
7/99/2018
7/99/2018
6/99/2015
4/12/2012
;
rajd1
Quartz | Level 8
Works perfect!
Reeza
Super User
if dateR =: '99/99' then do;
date_want = mdy(7, 1, input(scan(dater, 3, '/'), 8.));
end;
else if scan(dater, 2, '/') = '99' then do;
date_want = mdy(input(scan(dater, 1, '/'), 8.), 15, input(scan(dater, 3, '/'), 8.));
end;
else date_want = input(date4, mmddyy10.);
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1282 views
  • 1 like
  • 3 in conversation