Hi SAS community,
I have a data set of observations for different months in different years (spanning over 100 years), with the monthly data arranged in 12 columns for each year as below:
Year jan feb mar apr may jun jul aug sep oct nov dec
1856 0.235 0.168 0.24 0.159 0.211 0.234 0.247 0.224 0.291 0.141 0.152 0.246
1857 0.231 -0.042 -0.058 0.024 -0.016 0.117 0.149 0.014 0.036 -0.117 -0.152 -0.266
1858 -0.204 -0.297 -0.054 0.228 0.106 -0.023 -0.144 -0.055 0.087 0.165 0.291 0.139
I want to convert the year-month data into a single long time series of julian dates, so that the observation of the first month in the first year (1856) gets assigned a julian date = 1856 + (0.5/12) = 1856.042, and so on. The output file should have the new date variable in its own column, and the corresponding observation for that julian date, as below:
1856.041 0.235
1856.125 0.168
1856.208 0.24
...etc.
Has anyone some suggestions or code to do this (in SAS version 9)?
Thanks for help.
/* UNTESTED CODE */
data want;
set have;
array x(*) jan--dec;
do i=1 to dim(x);
juldate = year+(i-0.5)/12;
value=x(i);
output;
end;
keep juldate value;
run;
/* UNTESTED CODE */
data want;
set have;
array x(*) jan--dec;
do i=1 to dim(x);
juldate = juldate(mdy(i,1,year));
value=x(i);
output;
end;
keep juldate value;
format juldate julian7.;
run;
For not standard values such as below, please indicate the actual date each is supposed to represent:
1856
0.792
1856.792
1856
0.875
1856.875
None of those resemble a Julian date in any form. Julian dates are YYDDD or YYYYDDD where Y is year and DDD is a 3-digit number of the day in a year.
I think you may also want to include some other months worked out just to make sure we understand how you are mangling month.
Hi,
Thank you for replying. What I need is not really a julian date, but a decimal year date. Sorry I did not make that clear enough in the original post. In the meantime another community member has solved the question. Please see the other posts in this thread for information.
/* UNTESTED CODE */
data want;
set have;
array x(*) jan--dec;
do i=1 to dim(x);
juldate = year+(i-0.5)/12;
value=x(i);
output;
end;
keep juldate value;
run;
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.