BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jdgriffin
Fluorite | Level 6

I am working with a small dataset (see attached) that has time coded into fractional years. For example: 1990.1456, 1991.3568, 1991.5689...

 

Is there an INFORMAT that would allow me to read this variable in as a SAS date?

 

Thank you for any help you can offer. 

 

-John

1 ACCEPTED SOLUTION
4 REPLIES 4
jdgriffin
Fluorite | Level 6

Thank you for the reply. So that I am understanding correctly, I am basically calculating the non-integer difference in years between my date and the SAS reference date, then converting it to integer days?

 

This is straight forward. I appreciate it. 

mkeintz
PROC Star

There is no such informat.

 

However,  you could calculate the date value (or is it really a datetime value?), by

  1. Extract the year portion, i.e. the integer
  2. Take the decimal portion and determine the corresponding datetime and multply by 24*60*60*(365 or 366) to get number of seconds into the  year if you want date-time values.

 

 

data want;
  set have;
  year=floor(time);

  /* Get number of seconds in the year, accomodating leap years */
  secondsinyear=24*60*60*intck('day',mdy(1,1,year),mdy(1,1,year+1));

  datetimevalue=dhms(mdy(1,1,year),0,0,0) +
                secondsinyear*mod(time,1);

  datevalue=datepart(datetimevalue);
  format datetimevalue datetime20. datevalue date9.;
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

--------------------------
jdgriffin
Fluorite | Level 6

Thanks for the reply. I suppose you are correct that it could be considered a datetime given its level of accuracy. I'll be sure to give this a try as well. 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2088 views
  • 3 likes
  • 3 in conversation