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

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?  

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller
Reeza
Super User

Are you doing a degree day type calculation?

SAS Innovate 2025: Call for Content

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!

Submit your idea!

What is Bayesian Analysis?

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.

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
  • 2 replies
  • 3087 views
  • 0 likes
  • 3 in conversation