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

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

 

25 July 2016 11:43:20

 

into a numeric datetime:

 

thanks

 

David

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

7 REPLIES 7
ballardw
Super User

Are the months always the full text, ie December ?

ballardw
Super User

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;
moorsd
Obsidian | Level 7
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.
Ksharp
Super User

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

Ksharp
Super User
ANYDTDTM. Powerful.

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

ballardw
Super User

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

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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