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

So I have a column that looks like this:

 

 

data time;

input  time $4.;

datalines;
0930
1000
0800
1300
1530
;
run;


 

 

and I want it to look like this:

 

09:30

10:00

08:00

13:00

15:30

 

Which is in a HHMM. or TIME. format

 

Tried the PUT statement and came back with an error


ERROR: The informat HHMM was not found or could not be loaded.

Is there any simple ways of doing this?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26
data time;
  input time $4.;
  time_calc=input(time,hhmmss4.);
  format time_calc time5.;
datalines;
0930
1000
0800
1300
1530
;
run;

View solution in original post

5 REPLIES 5
andreas_lds
Jade | Level 19

Maybe i am blind, but i don't see the mentioned put statement in your code.

 

Index of informats: https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#n0verk17pch...

 

I suggest using "hhmmss" instead of "hhmm".

ppchennn
Fluorite | Level 6
Sorry I failed to include that in my post! So I guess using hhmmss instead of hhmm is because SAS calculates time based on seconds?
RW9
Diamond | Level 26 RW9
Diamond | Level 26
data time;
  input time $4.;
  time_calc=input(time,hhmmss4.);
  format time_calc time5.;
datalines;
0930
1000
0800
1300
1530
;
run;
ppchennn
Fluorite | Level 6
Thanks a lot! Now I know what I'm doing wrong.
RahulG
Barite | Level 11

I could not find relevant format to read it direclty. But you can use below code to get desired result.

 

data time(keep=t1 time);

input  time $4.;
t1=substr(time,1,2)*3600 +substr(time,3,2)*60 ;
format t1 time5.;
datalines;
0930
1000
0800
1300
1530
;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 10519 views
  • 4 likes
  • 4 in conversation