IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

SAS: PROC REPORT


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Wed Mar 23, 2011 2:52 pm
Reply with quote

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
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Wed Mar 23, 2011 9:20 pm
Reply with quote

Include a BY year; statement in your proc statements.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Mar 23, 2011 9:46 pm
Reply with quote

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
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Thu Mar 24, 2011 2:47 pm
Reply with quote

Maybe you could use "PROC MEANS" in stead of "PROC REPORT"
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Thu Mar 24, 2011 9:46 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Mar 24, 2011 10:51 pm
Reply with quote

Glad to hear it's working.

PROC MEANS is nice but PROC UNIVARIATE gives you more information for the same effort!
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> All Other Mainframe Topics

 


Similar Topics
Topic Forum Replies
No new posts Need help on formatting a report DFSORT/ICETOOL 14
No new posts Creating Report using SORT DFSORT/ICETOOL 7
No new posts Ca7 long running jobs report All Other Mainframe Topics 1
No new posts Report of batch jobs JCL & VSAM 1
No new posts z/OS Modules Usage report using SMF 42 DFSORT/ICETOOL 2
Search our Forums:

Back to Top