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

Hi All,

I have variable I need converted from a number to a time value.  The format now is 15, 30, 45, 100, 115 and I want 12:00AM, 12:15AM, 12:30AM, 12:45AM 1:00AM etc.

Steve

1 ACCEPTED SOLUTION

Accepted Solutions
CTorres
Quartz | Level 8

This is Mark Johnson' solution improved:

data want;

set have;

txt=put(number,z4.);

time = put(input(substr(txt,1,2),2.)*3600+(input(substr(txt,3),2.)*60),timeampm.);

drop txt;

run;

CTorres

View solution in original post

6 REPLIES 6
Ron_MacroMaven
Lapis Lazuli | Level 10

RTFM on the

TIMEAMPMw.d Format

attrib MyTimeVar length = 8 format =timeampm5.2;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post some test data (as a datastep).  At a guess:

Step 1 - split the variable and convert to minutes (note the best coding method, but its to show the process):

data want;

     set have;

     i=1;

     do while (scan(variable,i,",") ne "");

          mins=input(scan(variable,i,","),best.);

          if mins=100 then mins=60;

          if mins=115 then mins=75;

          new_time="12:00"t + mins;

          output;

     end;

run;

Steelers_In_DC
Barite | Level 11

Are you sure 100 should be 1:00 am?  You go from 45 minutes to 100 minutes, logically 45 = 12:45am and 100 = 1:00am doesn't jive:

data have;

input number;

cards;

15

30

45

100

115

;

run;

data want;

set have;

time = put(number*60,timeampm.);

run;

Tommywhosc
Obsidian | Level 7

Are you saying that your actual data values are HOUR:MINUTE, but w/o the colon?

0245 (the integer) <=> 02:45 (the time)??

If so, then pull out the hour, minute values, convert to seconds.

(but w/o any data, we're just guessing).

data want; set have;

minutes = mod(badtime,100);

hours = floor(badtime/100);

seconds = hours*3600 + minutes*60;

format seconds timeampm. ;

run;

CTorres
Quartz | Level 8

This is Mark Johnson' solution improved:

data want;

set have;

txt=put(number,z4.);

time = put(input(substr(txt,1,2),2.)*3600+(input(substr(txt,3),2.)*60),timeampm.);

drop txt;

run;

CTorres

BU2B
Calcite | Level 5

Thanks guys!  I'm sure all of them would work, but I got the last one to work first.  Thanks again!

Steve

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 2443 views
  • 6 likes
  • 6 in conversation