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

I have a date/time character string that looks like this:

 

02OCT07:2240

03APR07:1825

02OCT07:2240

 

I need some help converting this into a datetime sas format.  I think some combination of input and scan?

 

Help is appreciated!

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14

There are many way you can do, just apply which one fits your needs. Here another way for your queston:

 

DATA test;
FORMAT DATE DATETIME14.;
DATE_CHAR='02OCT07:2240';
DATE=INPUT(CATX(":",SUBSTR(DATE_CHAR,1,10),SUBSTR(DATE_CHAR,11)),DATETIME14.);
RUN;
Thanks,
Suryakiran

View solution in original post

3 REPLIES 3
Reeza
Super User

Did you try INPUT with the ANYDTDTM. informat?

Shmuel
Garnet | Level 18

Read the input variable as a string, split it and then convert it to sas date/time variables.

See next code example:

 

data dtime;
      string = '02OCT07:2240';

     date = input(scan(string,1,':'), date7.);
     hh = input(substr(string,9,2),2.);
     mm = input(substr(string,11,2),2.);

     dtime = dhms(date,hh,mm,0);

    format date date9.    /* check also ddmmyy10. */
               dtime datetime15.;
run;

check the result of above code and adapt it to your needs.

SuryaKiran
Meteorite | Level 14

There are many way you can do, just apply which one fits your needs. Here another way for your queston:

 

DATA test;
FORMAT DATE DATETIME14.;
DATE_CHAR='02OCT07:2240';
DATE=INPUT(CATX(":",SUBSTR(DATE_CHAR,1,10),SUBSTR(DATE_CHAR,11)),DATETIME14.);
RUN;
Thanks,
Suryakiran

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
  • 3 replies
  • 20605 views
  • 4 likes
  • 4 in conversation