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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.