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;
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.
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.;
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;
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!
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.