I have a variable time which represents total elapsed time, not a time on the 24hr clock. For example, 1459 means 14 hours and 59 minutes elapsed and 9 simply means 9 minutes elapsed. It came in as a string and I am trying to convert it to a numerical value in total minutes. Below is the have and want data. I am struggling to find informats that aren't based on the 24hr clock.
data have;
input claim_id $ time $;
cards;
3 9
2 14
98 349
99 1459
;
run;
data want;
input claim_id $ time $ time_min;
cards;
3 9 9
2 14 14
98 349 229
99 1459 899
;
run;
data have;
input claim_id $ time ;
if time > 60 then do;
time=(int(time/100)*60)+mod(time,100)
end;
cards;
3 9
2 14
98 349
99 1459
;
run;
Consider:
data have; input claim_id $ time ; time = time*60; format time time.; cards; 3 9 2 14 98 349 99 1459 ; run;
SAS time values are stored as a number of seconds. So multiply minutes by 60. Or
time_min = input(time, best.)*60;
if your value is character already.
time_char = put(time, z4.) ;
hours = input(substr(time_char,1,2),2.);
minutes = input(substr(time_char,3),2.);
time_min = hours * 60 + minutes;
data have;
input claim_id $ time ;
if time >60 then do;
time=int(time/100)+mod(time,100);
end;
cards;
3 9
2 14
98 349
99 1459
;
run;
data have;
input claim_id $ time ;
if time > 60 then do;
time=(int(time/100)*60)+mod(time,100)
end;
cards;
3 9
2 14
98 349
99 1459
;
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.