This informat I cannot find. When I use the ANYDTDTE7. informat it comes up with the incorrect SAS date.
data want;
given_date='Jan-20-19';
length _t1 $9;
do _i=2,1,3;
_t1=cats(_t1,scan(given_date,_i,'-'));
end;
want_date=input(_t1,date9.);
drop _:;
format want_date date9.;
run;
Does MMM mean you have a three-letter month name?
In this case, you will have to reshuffle the string before converting:
data have;
input str_date :$9.;
datalines;
jan-01-19
mar-28-18
;
data want;
set have;
num_date = input(substr(str_date,5,2)!!substr(str_date,1,3)!!substr(str_date,8,2),date7.);
format num_date e8601da10.;
run;
data want;
given_date='Jan-20-19';
length _t1 $9;
do _i=2,1,3;
_t1=cats(_t1,scan(given_date,_i,'-'));
end;
want_date=input(_t1,date9.);
drop _:;
format want_date date9.;
run;
@Astounding wrote:
Have you tried ANYDTDTE9. ?
When the date contains 9 characters but your informat only reads 7 characters, expect the results to be unusual.
I tried it and fails. But interestingly enough
data want; given_date='Jan-20-2019'; date = input(given_date,anydtdte11.); format date date9.; run;
seems to work just fine. Yet another reason NOT to use 2 digit years.
BTW
data want; given_date='Jan-20-2019'; date = input(given_date,anydtdte.); format date date9.; run;
Fails as well.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.