View previous topic :: View next topic
|
Author |
Message |
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
Hi,
I have an input SAS dataset which looks like, (it has beer sales numbers based on the temperature)
Code: |
month sales hightemp lowtemp
1 130.2 3.5 -3.2
2 137.0 6.9 0.8
3 171.4 11.5 2.9
4 178.5 13.0 4.7
5 211.9 16.9 8.6
6 227.4 19.9 10.3
7 253.8 22.7 13.0
8 254.6 22.1 13.2
9 152.5 19.4 11.5
10 177.2 13.9 7.1
11 161.8 8.8 0.8
12 179.3 8.6 3.1
13 156.8 3.7 -2.8
14 130.4 8.4 2.9
15 166.1 8.8 2.5
16 205.4 14.2 5.7
17 209.1 16.0 8.5
18 235.4 17.8 10.6
19 227.3 20.7 12.4
20 203.9 20.3 10.2
21 182.5 17.5 10.3
22 200.4 15.0 6.5
23 161.0 9.8 4.1
24 195.9 7.1 2.7 |
I am trying to create a yearly summary report which looks like,
Code: |
Year Sales hightemp lowtemp
1 mean of sales from month1-month12 mean of hightemp mean of low temp
2 mean of sales from month13-month24 mean of hightemp mean of low temp |
I tried the below code,
I am able to compute 'year' variable values, but I don't know how to GROUP on 'year' variable value which is computed.
Code: |
proc report data = xx.sales nowd headline headskip center;
column month year sales ('-Temperature-' hightemp lowtemp);
define month / analysis noprint;
define year / computed 'Year' width = 5;
define sales / display 'SALES' width = 5;
define hightemp / display sum 'Hightemp' width = 8;
define lowtemp / display sum 'Lowtemp' width = 7;
compute year;
if mod(month.sum,12) = 0 and int(month.sum/12) = 0 then
year = 1;
else if mod(month.sum,12) = 0 then year = int(month.sum/12);
else year = int(month.sum/12) + 1;
endcomp;
run; |
Output of above code;
Code: |
---Temperature---
Year SALES Hightemp Lowtemp
-------------------------------
1 130.2 3.5 -3.2
1 137 6.9 0.8
1 171.4 11.5 2.9
1 178.5 13 4.7
1 211.9 16.9 8.6
1 227.4 19.9 10.3
1 253.8 22.7 13
1 254.6 22.1 13.2
1 152.5 19.4 11.5
1 177.2 13.9 7.1
1 161.8 8.8 0.8
1 179.3 8.6 3.1
2 156.8 3.7 -2.8
2 130.4 8.4 2.9
2 166.1 8.8 2.5
2 205.4 14.2 5.7
2 209.1 16 8.5
2 235.4 17.8 10.6
2 227.3 20.7 12.4
2 203.9 20.3 10.2
2 182.5 17.5 10.3
2 200.4 15 6.5
2 161 9.8 4.1
2 195.9 7.1 2.7 |
Please let me know how this can be done using PROC REPORT? |
|
Back to top |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
Include a BY year; statement in your proc statements. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Calculate YEAR before the PROC REPORT and get rid of the COMPUTE CODE. Instead use
Code: |
proc report data = sales nowd headline headskip center;
column year sales ('-Temperature-' hightemp lowtemp) ;
define year / group 'Year' width = 5;
define sales / analysis mean 'SALES' width = 5;
define hightemp / analysis mean 'Hightemp' width = 8;
define lowtemp / analysis mean 'Lowtemp' width = 7; |
|
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Maybe you could use "PROC MEANS" in stead of "PROC REPORT" |
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
Hi,
Thanks for the suggestions.
As Robert said i removed the years variable and the output was correct.
used proc format to replace month variable,
Code: |
proc format;
value years. 1-12 = 1
13-24=2
25-36=3
.
.
; run;
define month / display 'Year' format=years.; |
Quote: |
Maybe you could use "PROC MEANS" in stead of "PROC REPORT" |
This was a self learning exercise on proc report, i still have not learnt using proc means yet. have to
Regards, |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Glad to hear it's working.
PROC MEANS is nice but PROC UNIVARIATE gives you more information for the same effort! |
|
Back to top |
|
|
|