BookmarkSubscribeRSS Feed
larkjr18
Fluorite | Level 6

Total_DOB = input(catx("/", month_dob, day_dob, year_dob),?? mmddyy8.);
if ((month_dob = 29) AND (day_dob= 02)) then Total_DOB = mdy(03,01,year_dob)-1;
else Total_DOB = mdy(month_dob,15,year_dob);

 

or

 

Total_DOB = input(catx("/", month_dob, day_dob, year_dob),?? mmddyy8.);
if ((Total_DOB = .) AND (month_dob = 29)) then Total_DOB = mdy(03,01,year_dob)-1; 
else Total_DOB = mdy(month_dob,15,year_dob);
 
neither work and just change all of the dates with a . to the day with 15
4 REPLIES 4
Jagadishkatam
Amethyst | Level 16

I would try the below approach if there are only two conditions

 

1) if the month_dob=02 and day_dob=29 then you want it to be imputed to 01MarYYYY. imputing only the day and month. if it is the case then what you mentioned is incorrect, you codes month_dob=29 which should be 02 as i mentioned so you reversed it.

 

2) if the above condition is not met then  you would like to impute only the day to 15.

 

Please let me know if these are only two conditions you are checking.

 

 

Thanks,
Jag
Astounding
PROC Star

Let's start with the most obvious issues and clear them up.  There might be more, but start with ...

 

Is YEAR_DOB really a two-digit year?  That would be the only reason to use ?? MMDDYY8.  But if YEAR_DOB is really a four-digit year, MMDDYY8 isn't long enough.  You need to switch to MMDDYY10. because you have to count the slashes as part of the characters you are reading.

 

It looks like you have switched around the month and the day.  It is highly unlikely that you will ever find MONTH_DOB=29.

PGStats
Opal | Level 21

Did you know that function MDY can handle two digits year values? If the problem is that you are sometimes missing the day value, then all you need is:

 

Total_DOB = mdy (month_dob, coalesce(day_dob, 15), year_dob);

format total_DOB yymmdd10.;

PG
Kurt_Bremser
Super User

First of all, are month_dob, day_dob, year_dob numeric or character? In your code snippet you treat them as both, which is at least not sound programming practice.

Assuming that they are numeric, I'd do

Total_DOB = input(put(year_dob,z4.) !! put(month_dob,z2.) !! put(day_dob,z2.),yymmdd8.);
if Total_DOB = .
then do;
  if ((month_dob = 29) and (day_dob = 2))
  then Total_DOB = mdy(3,1,year_dob)-1;
  else if day_dob = .
  then Total_DOB = mdy(month_dob,15,year_dob);
end;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 713 views
  • 1 like
  • 5 in conversation