The nested TRANWRDs put forth by the OP would improperly process "JUN" in the month component, so text like
2001JUN15 would be converted to 2001J0115 prior to a failed attempt to convert it to a date value, as below:
data _null_;
do date='2001FEBUN','2001UNKUN','2001UNK15','2001MAR15', '2001JUN15';
date_new=input(tranwrd(tranwrd(upcase(date), 'UNK', 'JAN'), 'UN', '01'),anydtdte.);
format date_new date9.;
put (_all_) (=);
end;
run;
But append a "!" to the DATE text, allows TRANWRD "UN!" to "01!", which avoids the "JUN" problem:
data _null_;
do date='2001FEBUN','2001UNKUN','2001UNK15','2001MAR15', '2001JUN15';
date_new=input(tranwrd(tranwrd(upcase(cats(date,'!')), 'UNK', 'JAN'), 'UN!', '01!'),anydtdte.);
format date_new date9.;
put (_all_) (=);
end;
run;
Fundamentally, I think you want to convert the character string dates to actual numeric SAS dates, rather than make them character strings that look like dates.
But since you don't give us examples of the input data, I can't be more specific.
I would steal your earlier code, and modify it
date_new=input(tranwrd(tranwrd(upcase(date), 'UNK', 'JAN'), 'UN', '01'),anydtdte.);
format date_new date9.;
I'm sure the prschange experts can advise, but I am not one of them.
Those are odd dates, with year, then month, then day.
The nested TRANWRDs put forth by the OP would improperly process "JUN" in the month component, so text like
2001JUN15 would be converted to 2001J0115 prior to a failed attempt to convert it to a date value, as below:
data _null_;
do date='2001FEBUN','2001UNKUN','2001UNK15','2001MAR15', '2001JUN15';
date_new=input(tranwrd(tranwrd(upcase(date), 'UNK', 'JAN'), 'UN', '01'),anydtdte.);
format date_new date9.;
put (_all_) (=);
end;
run;
But append a "!" to the DATE text, allows TRANWRD "UN!" to "01!", which avoids the "JUN" problem:
data _null_;
do date='2001FEBUN','2001UNKUN','2001UNK15','2001MAR15', '2001JUN15';
date_new=input(tranwrd(tranwrd(upcase(cats(date,'!')), 'UNK', 'JAN'), 'UN!', '01!'),anydtdte.);
format date_new date9.;
put (_all_) (=);
end;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.