Hi, I am pretty new to SAS programming and teaching myself out of necessity. I am trying to figure out the consecutive days that mean daily water temperature remained below a threshold temperature (8 degrees Celsius).
Here is an example of what my data looks like:
Minimum Maximum Mean Count Station Date
4.1 10.6 7.9 1 20160102
4.2 9.1 7.6 1 20160103
4.0 8.9 7.3 1 20160104
4.0 9.0 7.4 1 20160105
3.9 8.9 7.0 1 20160106
4.1 9.2 7.9 1 20160107
4.4 10.4 7.8 1 20160108
For station date, the date is set up as yyyymmdd. This can be changed if need be, this is just how we input dates in our database. Minimum, maximum, and mean all refer to water temperature
I've already separated all of the mean water temperature data below 8 o C, and all I want are the maximum consecutive days for each year (meaning the maximum number of CONSECUTIVE days that the temperature was below 8 o C. My year data range from 1991-2017.
I've tried out some code, but nothing has been very successful yet. I tried modifying this tutorial :http://support.sas.com/kb/33/838.html, but I'm having trouble discerning where parts of the data example come from.
This is the data I want:
Year Maximum Consecutive Days
1991 20
1992 34
1993 42
1994 26
(for example). What kind of procedure can I use to achieve this?
Assuming your dates are actual SAS dates and not character strings:
data want;
set have;
year=year(station_date);
if month(station_date)=1 and day(station_date)=1 then consec=0;
if mean<8 then consec+1;
else if mean>=8 then consec=0;
run;
Then you can use PROC SUMMARY to obtain the max values of variable CONSEC in each year;
Assuming your dates are actual SAS dates and not character strings:
data want;
set have;
year=year(station_date);
if month(station_date)=1 and day(station_date)=1 then consec=0;
if mean<8 then consec+1;
else if mean>=8 then consec=0;
run;
Then you can use PROC SUMMARY to obtain the max values of variable CONSEC in each year;
Are you doing a degree day type calculation?
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.