Please show example values and expected results.
data have;
input string1 $9.;
cards;
23JAN2022
UNFEB2021
UNUNK2020
;
data want;
set have;
length string2 $8;
date = input(string1,??date9.);
if not missing(date) then string2=put(date,yymmddn8.);
else do;
if string1 =: 'UNUN' then string2=substr(string1,6);
else if string1 =: 'UN' then do;
date = input(substr(string1,3),monyy7.);
if not missing(date) then string2=put(date,yymmn6.);
end;
end;
format date yymmdd10.;
run;
proc print;
run;
