Solved
Contributor
Posts: 35

# how to create this report classified by k

how to create this report classified by k?

Thanks

data have;

input x y z k \$;

cards;

1 2 3 a

1 1 3 a

5 2 3 a

0 3 5 a

3 1 3 b

1 3 3 b

1 3 5 b

0 1 3 b

6 5 3 b

1 0 3 b

4 2 5 a

1 4 3 a

0 1 3 a

;

run;

ods listing close;

ods tagsets.excelxp file='H:\My Documents\total29.xls' style=sasweb

options(default_column_width="5,10,10"  )

;

proc report data=have nowd;

column x y z k;

define x/display;

define y/analysis sum;

define z/analysis mean;

define k/group ;/*not work*/

rbreak before/summarize;

run;

ods tagsets.excelxp close;

ods listing;

Accepted Solutions
Solution
‎04-18-2012 11:03 AM
SAS Super FREQ
Posts: 9,365

## Re: how to create this report classified by k

Hi: Take a look at these two reports. Asking for the mean statistic for Z doesn't make sense if you are going to just DISPLAY all the values of X. For example, you have K=A and X=0 for two observations:

x y z k

0 3 5 a

0 1 3 a

So what do you want to see for the MEAN statistic on the Z column the individual values of 5 and 3 or do you want to see one row with 5+3/2????

See attached screen shots -- using your data and different usages for K and X. If you want to show the MEAN only at the break, then that is possible using ORDER usage for K and X; but if you want the MEAN for every unique combination of K and X, then you should have GROUP usage for both K and X.

cynthia

All Replies
Super Contributor
Posts: 350

## Re: how to create this report classified by k

Hi,

Try this..

proc report data=have nowd;

column x y z k;

define x/'x';

define y/analysis sum;

define z/analysis mean;

define k/group ;/*not work*/

rbreak before/summarize;

run;

Thanks,

Shiva

SAS Super FREQ
Posts: 9,365

## Re: how to create this report classified by k

Hi:

What do you mean when you say, "classified by k" -- does that mean you want to see all the values for 'a' together and then all the values for 'b' together???? Then do you want to see X, Y and Z as totals for each value of K or do you want to see every individual row for K on the report????

Thanks for showing the program, but a bit more info is needed to understand what you want. I'm not sure what your comment "/* not work */" means -- usually, if you want to GROUP on K, you would list it first in the COLUMN statement. As suggested by Shiva, with a usage of DISPLAY for the variable X, you will not get collapsing or totals -- if X is numeric, then taking off the usage of DISPLAY will cause you to get summary numbers for X, Y and Z.

Did you run the modified code? Is it what you anticipated or wanted?

cynthia

Contributor
Posts: 35

## Re: how to create this report classified by k

Thank you Shivas and Cynthia!

the result of y and z is exact what I want,but x is just for display the original values but not for summation.

proc report data =have

out =want6
nowindows
;
column x y z k new1;
define k / group ;
define x/ display ; /*This will cause problem,I want display all the X a, also I want the sum of y and z by k*/
define y / analysis sum ;
define z / analysis sum ;
define new1     / computed ;
define new2     / computed ;
compute new1;
new1 = y.sum *k;
endcomp;

rbreak before/summarize;
run;

Super Contributor
Posts: 350

## Re: how to create this report classified by k

Hi..

Is this the output you required..

proc report data=have nowd;

column x (y, sum)(z, mean) k;

define x/'x'  display;

define y/display;

define z/display;

define k/group ;/*not work*/

rbreak before/summarize;

run;

Thanks,

Shiva

SAS Super FREQ
Posts: 9,365

## Re: how to create this report classified by k

Hi:

K is a character variable. I don't understand what you are trying with this statement:

compute new1;

new1 = y.sum *k;

endcomp

you can never multiply a number by a character value.

cynthia

Solution
‎04-18-2012 11:03 AM
SAS Super FREQ
Posts: 9,365

## Re: how to create this report classified by k

Hi: Take a look at these two reports. Asking for the mean statistic for Z doesn't make sense if you are going to just DISPLAY all the values of X. For example, you have K=A and X=0 for two observations:

x y z k

0 3 5 a

0 1 3 a

So what do you want to see for the MEAN statistic on the Z column the individual values of 5 and 3 or do you want to see one row with 5+3/2????

See attached screen shots -- using your data and different usages for K and X. If you want to show the MEAN only at the break, then that is possible using ORDER usage for K and X; but if you want the MEAN for every unique combination of K and X, then you should have GROUP usage for both K and X.

cynthia

🔒 This topic is solved and locked.