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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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


k_x_group_correct.jpgk_x_order_correct.jpg

View solution in original post

6 REPLIES 6
shivas
Pyrite | Level 9

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

Cynthia_sas
SAS Super FREQ

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

George_S
Fluorite | Level 6

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;

shivas
Pyrite | Level 9

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

Cynthia_sas
SAS Super FREQ

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

Cynthia_sas
SAS Super FREQ

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


k_x_group_correct.jpgk_x_order_correct.jpg

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 6 replies
  • 1439 views
  • 7 likes
  • 3 in conversation