Contributor
Posts: 56

# time factors

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

Frequent Contributor
Posts: 93

## Re: time factors

Sorry, could you put "have" and "want" datasets, so that we can see the desired outcome for each of your circumstances?

Super User
Posts: 13,563

## Re: time factors

Before we go too far down suggestions are any of your date  or time variables SAS date or time values or character?

Contributor
Posts: 56

## Re: time factors

Thanks!   time fields are of character settings.

Posts: 1,345

## Re: time factors

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;

Contributor
Posts: 56

## Re: time factors

[ Edited ]

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!!

Discussion stats
• 5 replies
• 262 views
• 0 likes
• 4 in conversation