Reputation: 15
I have a field that has dates in it in character format that display as 31-DEC-2020 or similar, and I need to convert them to mmddyy10.
How would I go about doing that? I have tried to use INPUT() so far, to no avail. Thanks!
Upvotes: 1
Views: 617
Reputation: 4658
What you are looking for is date_var = input(str_var, date11.)
.
/* test data */
data have;
input s $ 1-11;
cards;
31-DEC-2020
01-jan-1970
;run;
/* code */
data want;
set have;
date = input(s, date11.);
format date date11.; /* display format need not be date11. */
run;
Result
s date
1 31-DEC-2020 31-DEC-2020
2 01-jan-1970 01-JAN-1970
The data type of the output dataset can be verified using proc contents data=want; run;
(omitted here).
See also this answer and the official docs.
Upvotes: 3