Part of your issue is you haven't broken the code up to identify all of your possible cases. 1) all values missing, 2) all but day missing, 3) all but month missing, 4) all but year missing, 5) ony missing day, 6) only missing month, 7) missing only year and finally 😎 missing no values.
For instance with your third record and the value of 02--1978
None of this code gets executed:
if day eq "-" and month eq "-" then year=substr(birthdate,3,4); else if day eq "-" and month ne "-" then year=substr(birthdate,6,4); else if year eq "-" then year="0000"; else if month eq "-" then year=substr(birthdate,5,4);
because "day" = 0, "month"=2 and "year"=7
And for the case where day is ne - and month ne - you never re-read the year so you get that single digit.
I'm answering this away from my SAS install and have an idea I can't test at this time that may be much simpler over all.
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.