The SAS Output Delivery System and reporting techniques

SGPLOT of means of variables (hourly)

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 89
Accepted Solution

SGPLOT of means of variables (hourly)

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. 


Accepted Solutions
Solution
‎07-06-2018 11:06 AM
SAS Super FREQ
Posts: 4,272

Re: SGPLOT of means of variables (hourly)

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


All Replies
Respected Advisor
Posts: 3,271

Re: SGPLOT of means of variables (hourly)

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

--
Paige Miller
Frequent Contributor
Posts: 89

Re: SGPLOT of means of variables (hourly)

Posted in reply to PaigeMiller
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.
Super User
Super User
Posts: 9,840

Re: SGPLOT of means of variables (hourly)

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.

Frequent Contributor
Posts: 89

Re: SGPLOT of means of variables (hourly)

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.

Solution
‎07-06-2018 11:06 AM
SAS Super FREQ
Posts: 4,272

Re: SGPLOT of means of variables (hourly)

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 204 views
  • 3 likes
  • 4 in conversation