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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: