BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1025 views
  • 3 likes
  • 4 in conversation