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

I want to create the interval from Today's 2pm to the next day's 2 pm.

And put the last price in to the interval.

 

date

time

price

20071025

13:57:30

100.312

20071025

15:37:30

100.064

20071026

11:50:04

100.05

20071026

17:18:09

99.992

20071027

17:12:09

99.998

 

I try use 

TIME30=intnx("Hour24.15", time, 0, "E");

 

But, I like to get the following dataset from the raw dataset.

20071025 13:59:59 100.312

20071026 13:59:59 100.05

20071027 13:59:59 99.992

20071028 13:59:59 99.998

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

'hour24.15' is right, but you need to apply it to datetime values, not just time values:

 

data have;
input date yymmdd8. time :time8.0 price;
format date date9. time time8.0;
datalines; 
20071025 13:57:30 100.312
20071025 15:37:30 100.064
20071026 11:50:04 100.05
20071026 17:18:09 99.992
20071027 17:12:09 99.998
run;


data need/view=need;
  set have;
  index_dt=dhms(date,0,0,0)+time; 
  index_dt=intnx('hour24.15',index_dt,0,'e'); 
  format index_dt datetime20.;
run;

data want (drop=index_dt); 
  set need;
  by index_dt;
  if last.index_dt;
  time=timepart(index_dt);
run;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

1 REPLY 1
mkeintz
PROC Star

'hour24.15' is right, but you need to apply it to datetime values, not just time values:

 

data have;
input date yymmdd8. time :time8.0 price;
format date date9. time time8.0;
datalines; 
20071025 13:57:30 100.312
20071025 15:37:30 100.064
20071026 11:50:04 100.05
20071026 17:18:09 99.992
20071027 17:12:09 99.998
run;


data need/view=need;
  set have;
  index_dt=dhms(date,0,0,0)+time; 
  index_dt=intnx('hour24.15',index_dt,0,'e'); 
  format index_dt datetime20.;
run;

data want (drop=index_dt); 
  set need;
  by index_dt;
  if last.index_dt;
  time=timepart(index_dt);
run;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore 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
  • 1 reply
  • 1073 views
  • 0 likes
  • 2 in conversation