DATA Step, Macro, Functions and more

time factors

Reply
Contributor
Posts: 28

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: 10,501

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: 28

Re: time factors

Thanks!   time fields are of character settings. 

Valued Guide
Posts: 797

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: 28

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')

 

TIMEminuteHOUR123456789101112
07:3838 00000003838383838

 

The next step would be to divide the minute by 60 to create a factor.

 

Thanks again for all of your help thus far!!

Ask a Question
Discussion stats
  • 5 replies
  • 191 views
  • 0 likes
  • 4 in conversation