BookmarkSubscribeRSS Feed
tobyfarms
Fluorite | Level 6

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

5 REPLIES 5
thomp7050
Pyrite | Level 9

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

ballardw
Super User

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

tobyfarms
Fluorite | Level 6

Thanks!   time fields are of character settings. 

mkeintz
PROC Star

@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;

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
tobyfarms
Fluorite | Level 6

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

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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