Reputation: 459
I have a sas dataset with a column called "date" in the format of yymmdd10., such as 2022-05-24.
I tried to covert it into the format of date9. as below, but it returns missing.
data want;
set have;
date1 = input(date,yymmdd10.);
format date1 date9.
run;
So I'd like to know what is the right code. Thanks!
Upvotes: 0
Views: 11708
Reputation: 51621
The date '24MAY2022'd is the number 22,790. To have it display as 24MAY2022 instead of 2022-05-24 just change the format used to display it.
data want;
set have;
format date date9. ;
run;
Your code is treating DATE as if it was a character variable. So SAS will first convert the number 22,790 into a string using the BEST12. format. Since your informat has a width of only 10 the INPUT() function will try to convert the first 10 characters of the 12 character string 22790
. But the string 227
cannot be interpreted as a date by that informat, hence the missing values.
Upvotes: 1
Reputation: 21294
Modify the appearance of the date in the data set without recreating the data set using PROC DATASETS.
title 'Initial format';
proc print data=have(obs=5);
var date;
run;
*modify format;
proc datasets lib=work nodetails nolist;
modify have;
format date date9.;
run;quit;
title 'New format';
proc print data=have(obs=5);
var date;
run;
Upvotes: 0