DATA Step, Macro, Functions and more

datetime informat - help

Accepted Solution Solved
Reply
Contributor
Posts: 39
Accepted Solution

datetime informat - help

Would anyone know the best informat to turn the following character value:

 

25 July 2016 11:43:20

 

into a numeric datetime:

 

thanks

 

David


Accepted Solutions
Solution
‎09-05-2016 04:22 PM
Super User
Posts: 10,550

Re: datetime informat - help

Here's one example that may help you.

data example;
   x="25 July 2016 11:43:20";
   z= dhms(input(cats( scan(x,1), substr(scan(x,2),1,3) , scan(x,3)),date9.),0,0,input(scan(x,4),time8.));
   format z datetime20.;
run;

View solution in original post


All Replies
Super User
Posts: 10,550

Re: datetime informat - help

Are the months always the full text, ie December ?

Solution
‎09-05-2016 04:22 PM
Super User
Posts: 10,550

Re: datetime informat - help

Here's one example that may help you.

data example;
   x="25 July 2016 11:43:20";
   z= dhms(input(cats( scan(x,1), substr(scan(x,2),1,3) , scan(x,3)),date9.),0,0,input(scan(x,4),time8.));
   format z datetime20.;
run;
Contributor
Posts: 39

Re: datetime informat - help

Thanks for the help, and I have to apologise for not getting back to you sooner. I've not been in work for a while so didn't get around to accepting your solution.
Super User
Posts: 9,691

Re: datetime informat - help


data example;
   x="25 July 2016 11:43:20  ";
   z=input(translate(strip(x),':',' '),anydtdtm32.);
   format z datetime20.;
run;
proc print;run;

Super User
Posts: 9,691

Re: datetime informat - help

ANYDTDTM. Powerful.

data example;
   x="25 July 2016 11:43:20  ";
   z=input(x,anydtdtm32.);
   format z datetime20.;
run;
proc print;run;

Super User
Posts: 10,550

Re: datetime informat - help


Ksharp wrote:
ANYDTDTM. Powerful.

data example;
   x="25 July 2016 11:43:20  ";
   z=input(x,anydtdtm32.);
   format z datetime20.;
run;
proc print;run;


Yields missing value for z in my install (boss still hasn't updated from 9.2). I tried that first thing so wasn't sure whether it would work on others.

Super User
Posts: 9,691

Re: datetime informat - help

Ou. Are you still using SAS9.2 . That is almost ten years ago .
I am using UE, it is working for me .

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 379 views
  • 1 like
  • 3 in conversation