BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

Someone sent me a data set that contain a column called time.

This column is numeric type ( no sas time/date) and have values of time .

For example:

value 145000  means hour:14  minutes: 50  second:00  ( so the format is HH:MM:SS).

What is the way to convert it into SAS time format?

Data have;
input time;
cards;
112800
145000
84800
204500
132500
130400
110800
123000
123400
90600
115600
101600
100800
73500
143000
104200
95900
100500
90300
120100
212900
104600
112700
153200
140300
24900
114000
160600
123800
101900
100800
202900
110500
75900
130000
231200
;
Run;
4 REPLIES 4
Kurt_Bremser
Super User

Create a PICTURE format which adds the colons:

proc format;
picture colons
  low-high = '00:00:00'
;
run,

then use it in a PUT/INPUT:

data want;
set have;
time = input(put(time,colons8.),time8.);
format time time8.;
run;

Untested, posted from my tablet.

 

Edit: after testing, changed the length of the COLONS format to 8 in the PUT function.

FreelanceReinh
Jade | Level 19

Alternatively, you can use the SAS-supplied Z6. format (to add the missing leading zero to values such as 84800) and B8601TM. informat:

time=input(put(time,z6.),b8601tm.);
format time time8.;
Ksharp
Super User
Data have;
input time;
want=hms(int(time/10000),int(mod(time,10000)/100),mod(time,100));
format want tod8.;
cards;
112800
145000
84800
204500
132500
130400
110800
123000
123400
90600
115600
101600
100800
73500
143000
104200
95900
100500
90300
120100
212900
104600
112700
153200
140300
24900
114000
160600
123800
101900
100800
202900
110500
75900
130000
231200
;
Run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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