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

Hi, I'm trying to get something like this, but not the part of double Y-axis but the part where I get the average for every hour for each variable. I don't know how to make the graph display the mean of each variable. I know I probably need to use PROC MEANS or PROC SUMMARY but I can't find anything online. I have a lot of observations.

Screen Shot 2018-07-06 at 9.28.51 AM.png

 

My data looks something like this:

Year

Month

Day

Hour

Load

Temperature

20010

1

1

0

70000

20.87

2009

1

1

1

68000

20.61

2011

1

1

2

67000

20.27

2009

1

1

3

66000

20.52

2009

1

1

4

65000

21.45

2010

1

1

5

66000

21.69

2009

1

1

6

67000

21.87

2009

1

1

7

69000

22.39

2009

1

1

8

69000

22.72

2009

1

1

9

70000

24.61

2011

1

1

10

71800

26.74

2009

1

1

11

72000

29.72

 

And goes on and on. 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

I've simulated some sample data so that everyone can work with the same data. Here's how to sort and use PROC MEANS to summarize the data:

 

proc format ;  
 value mn_name 
    1='January'   2='February'  3='March'     4='April'
    5='May'       6='June'      7='July'      8='August'
    9='September' 10='October' 11='November' 12='December'
    other='Invalid';
run;
/* simulate time series data */
data Have;
call streaminit(1);
do year = 2009 to 2011;
   do month = 1 to 12;
      if month=2 then NDays=28;
      else if month in (4,6,9,11) then NDays = 30;
      else NDays=31;
      do Day = 1 to NDays;
      do hour = 0 to 23;
         load = 80 + 5*sin(hour/12*constant('pi')) + rand("Normal");
         temperature = 30 + 5*sin((hour+1)/12*constant('pi')) + rand("Normal");
         output;
      end;
      end;
   end;
end;
run;

proc sort data=Have;
by month hour;
run;

proc means data=Have noprint;
by month hour;
var load temperature;
output out=MeanOut mean=;
run;

proc sgpanel data=MeanOut;
format month mn_name.;
panelby month / layout=panel columns=2;
series x=Hour y=Temperature;
run;

The SGPANEL procedure does not support multiple Y axes, although you can use the GTL to display the Y2 axis.

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

The solution is to run PROC SUMMARY to create means, and then run PROC SGPLOT using the means computed by PROC SUMMARY.

--
Paige Miller
matt23
Quartz | Level 8
do you have any example code? Sorry, that's how I learn to code in SAS. Otherwise, I know what you mean but have to idea how to execute it.
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use proc means, then plot the output of the proc means.  The sgplot will run a lot quicker, and thus the proc means run time is negligible.

matt23
Quartz | Level 8

do you have any example code? Sorry, that's how I learn to code in SAS. Otherwise, I know what you mean but have to idea how to execute it.

Rick_SAS
SAS Super FREQ

I've simulated some sample data so that everyone can work with the same data. Here's how to sort and use PROC MEANS to summarize the data:

 

proc format ;  
 value mn_name 
    1='January'   2='February'  3='March'     4='April'
    5='May'       6='June'      7='July'      8='August'
    9='September' 10='October' 11='November' 12='December'
    other='Invalid';
run;
/* simulate time series data */
data Have;
call streaminit(1);
do year = 2009 to 2011;
   do month = 1 to 12;
      if month=2 then NDays=28;
      else if month in (4,6,9,11) then NDays = 30;
      else NDays=31;
      do Day = 1 to NDays;
      do hour = 0 to 23;
         load = 80 + 5*sin(hour/12*constant('pi')) + rand("Normal");
         temperature = 30 + 5*sin((hour+1)/12*constant('pi')) + rand("Normal");
         output;
      end;
      end;
   end;
end;
run;

proc sort data=Have;
by month hour;
run;

proc means data=Have noprint;
by month hour;
var load temperature;
output out=MeanOut mean=;
run;

proc sgpanel data=MeanOut;
format month mn_name.;
panelby month / layout=panel columns=2;
series x=Hour y=Temperature;
run;

The SGPANEL procedure does not support multiple Y axes, although you can use the GTL to display the Y2 axis.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 5 replies
  • 1663 views
  • 3 likes
  • 4 in conversation