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

i have the time data as follows;

 

Timestamp          Price

03:45:23:555       234

03:45:45:323       264

03:46:01:234       264

03:46:34:123       265

 

These are steps what i did and want to do with the data

-I have read the data in $12. informat since i couldnt do it in numeric # if can be done in numeric, help me.

-then changed it into numeric format using input function.

-i want to get the minute only but not succeeded

 

I have to create a minute interval from it, use  in Do loops to get ther required data from within the interval of minute.

 

That would be a great HELP.

 

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @gnrslasher37,

 

You can create SAS time values from your 12-character strings. These in turn can be truncated to minutes. The resulting time values (hh:mm) define groups of observations, for which you can derive the first, last, lowest, highest, average, ... price. If your dataset contains data from more than one date, you should also take care of the dates, though.

data want;
input ct :$12. price;
t=input(compress(ct,':'), b8601tm9.); /* SAS time value */
ttm=hms(hour(t),minute(t),0); /* time truncated to minutes */
format t   e8601tm12.3
       ttm tod5.;
cards;
03:45:23:555 234
03:45:45:323 264
03:46:01:234 264
03:46:34:123 265
;

proc print data=want;
run;

PS: In future posts I'm sure you'll be able to come up with a more informative title than "help".

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hi @gnrslasher37,

 

You can create SAS time values from your 12-character strings. These in turn can be truncated to minutes. The resulting time values (hh:mm) define groups of observations, for which you can derive the first, last, lowest, highest, average, ... price. If your dataset contains data from more than one date, you should also take care of the dates, though.

data want;
input ct :$12. price;
t=input(compress(ct,':'), b8601tm9.); /* SAS time value */
ttm=hms(hour(t),minute(t),0); /* time truncated to minutes */
format t   e8601tm12.3
       ttm tod5.;
cards;
03:45:23:555 234
03:45:45:323 264
03:46:01:234 264
03:46:34:123 265
;

proc print data=want;
run;

PS: In future posts I'm sure you'll be able to come up with a more informative title than "help".

Jim_G
Pyrite | Level 9

Input the first 8 characters of you time stamp with informat  Time8.  That converts the time to sas internal format, time in seconds. 

Divide by 60 to get minutes.

 

data;
input stime time8.;
stime=stime/60;
cards;        ***  one hour  equals 60 min;
01:00:00
proc print; run;

 

60

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

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
  • 2 replies
  • 1443 views
  • 0 likes
  • 3 in conversation