BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JW_Hyde
Obsidian | Level 7

This informat I cannot find. When I use the ANYDTDTE7. informat it comes up with the incorrect SAS date. 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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;

View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User

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;
JW_Hyde
Obsidian | Level 7
Thanks very much for the quick response.


novinosrin
Tourmaline | Level 20
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;
JW_Hyde
Obsidian | Level 7
Thanks very much for your quick response. This solution works the best for what I need.


Astounding
PROC Star
Have you tried ANYDTDTE9. ?

When the date contains 9 characters but your informat only reads 7 characters, expect the results to be unusual.
ballardw
Super User

@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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 3119 views
  • 2 likes
  • 5 in conversation