BookmarkSubscribeRSS Feed
sdang
Quartz | Level 8

Hi all, I want to convert StartTime and EndTime which are character variable to datetime variable so I can do calculation.  Please see our they are structured in my data source.

Capture.PNG

For example, the first row, I want my calculation to say that customer  started at 11:00 AM and ended 11:00 AM.  You are welcome to offer me another option of getting my desire calculation without any conversion.

Thank you ahead.

2 REPLIES 2
BrunoMueller
SAS Super FREQ

You can convert these type of text strings using the ANYDTDTM informat. Unfortunately it will not read the milliseconds. In the code below two methods are shown, one using the ANYDTDTM informat, the other uses a combination of two informats for the date and time part and then combine the date and seconds together using the DHMS function.

data want;
  dateHave = "2015.03.03 11:19:41.440";

  dateWant = input(dateHave,
anydtdtm19.);

  dateWant2 = dhms(
    input(substr(dateHave,
1, 10), yymmdd10.)
    ,
0
    ,
0
    , input(substr(dateHave,
12), time16.)
  );

 
format dateWant: datetime22.3;
run;
sdang
Quartz | Level 8

Thank you, it was helpful.

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 1289 views
  • 3 likes
  • 2 in conversation