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
Try this:
data want;
input dateval;
dateval = round((dateval - 1960) * 365.2425,1);
format dateval yymmddd10.;
cards;
1990.1456
1991.3568
1991.5689
run;
Try this:
data want;
input dateval;
dateval = round((dateval - 1960) * 365.2425,1);
format dateval yymmddd10.;
cards;
1990.1456
1991.3568
1991.5689
run;
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.
There is no such informat.
However, you could calculate the date value (or is it really a datetime value?), by
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;
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.