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