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.);

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 485 views
  • 1 like
  • 3 in conversation