Hello,
My variable DateofDiagnosis is a list of dates. Some have 99 for the day, 99 for the month, and 9999 for the year.
I want to replace ??/99 as "15/06", and replace ??/??/9999 as "".
This is my data
I replaced trailing values using
but I can't figure out how to replace the leading values.
I tried
But 0 real changes were made.
Edit: I also tried
but this led to 0 real changes being made.
What am I missing? Is there a simpler way to do this?
My variable DateofDiagnosis is a list of dates. Some have 99 for the day, 99 for the month, and 9999 for the year.
I want to replace ??/99 as "15/06", and replace ??/??/9999 as "".
This is my data
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str10 DateofDiagnosis "08/99/1997" "12/99/1999" "10/99/1999" "03/99/1996" "99/99/1977" "99/99/9999" end
Code:
replace DateofDiagnosis = "" if substr(DateofDiagnosis, -4, .) == "9999"
I tried
Code:
replace DateofDiagnosis = "15/06" + substr(DateofDiagnosis, -5, .) if subst(DateofDiagnosis, -7, -6) == "99"
Edit: I also tried
Code:
replace DateofDiagnosis = subinstr(DateofDiagnosis, "??/99", "15/06", .)
What am I missing? Is there a simpler way to do this?
Comment