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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: