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

The attached dataset has time in 24 hour format, see below:

000257

000341

000419

000433

000437

000451

002538

002719

002903

003029

003135

003141

So 133846 indicates 1 pm 38 minutes 46 seconds.  But the value is in string.  How could I convert the TIME string into SAS time?  I used the following code:

data WANG;

     set HAVE;

     time_numeric = input(time, time5.);

run;

But it doesn't seem to work.  SAS reports:

NOTE: Invalid argument to function INPUT at line 24 column 8.

time=000257 timej=. _ERROR_=1 _N_=11

NOTE: Invalid argument to function INPUT at line 24 column 8.

time=000341 timej=. _ERROR_=1 _N_=12

Could you guys help me~~

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Do this:

data wang;

set have;

  format time_numeric time8.;

  time_numeric = input(substr(time,1,2) !! ':' !! substr(time,3,2) !! ':' !! substr(time,5,2),time8.);

run;

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

Do this:

data wang;

set have;

  format time_numeric time8.;

  time_numeric = input(substr(time,1,2) !! ':' !! substr(time,3,2) !! ':' !! substr(time,5,2),time8.);

run;

pradeepalankar
Obsidian | Level 7

Hi ,

Use  time_numeric=input(time,hhmmss6.);


this should read your time.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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