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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.