I'm trying to capture the factor for each hour in the day, showing hours less than time should equal 0. so for the 1st line, hours 1-6 should equal 0, then hour 7 will take the minute/60.
*then completing this formula for every row in the dataset.
Date Time Minute
01JAN2017 07:38 38
01JAN2017 17:04 04
02JAN2017 07:38 38
02JAN2017 17:05 05
Sorry, could you put "have" and "want" datasets, so that we can see the desired outcome for each of your circumstances?
Before we go too far down suggestions are any of your date or time variables SAS date or time values or character?
Thanks! time fields are of character settings.
@tobyfarms wrote:
I'm trying to capture the factor for each hour in the day, showing hours less than time should equal 0. so for the 1st line, hours 1-6 should equal 0, then hour 7 will take the minute/60.
*then completing this formula for every row in the dataset.
Date Time Minute
01JAN2017 07:38 38
01JAN2017 17:04 04
02JAN2017 07:38 38
02JAN2017 17:05 05
I guess what you want is to create multiple output records for each input record, with one record for each hour from 0 (or maybe from 1) through the hour component of your time variable. And new var factor=0 for all hours except the last, when factor equals the fraction of minutes into that hour. If so ...
data want;
set have;
hmax=input(scan(time,1,':'),2.);
factor=0;
if hmax>0 then do hour=0 to hmax-1;
output;
end;
hour=hmax;
factor = input(minute,2.)/60; /*Assuming MINUTE is a character variable */
output;
run;
Thank you! I get slightly closer with that. What I am trying to do is take time (this time is an imported field and not date/time format) and hit it compared across a 24hr timeline.
The equation should be similar to :
If ('TIME' > 'Hour',then 0,else 'Minute')
TIME | minute | HOUR | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
07:38 | 38 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 38 | 38 | 38 | 38 | 38 |
The next step would be to divide the minute by 60 to create a factor.
Thanks again for all of your help thus far!!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.