## multiple statistics in proc report

Solved
Occasional Contributor
Posts: 12

# multiple statistics in proc report

Hello all:

I have a data file that contains survival times of mice under different groups.

mouse.dat:

"index" "Time" "Cause"          "Group"

"1"        159      "lymphopma" "germfree"

"2"        189      "sarcoma" "control"

.....

Say, I want to display the number and the percentages of mice that died due to different dieases(cause) using proc report. e.g something like

N       percentage

lymphopma        51       0.51

sarcoma            49       0.49

However, I don't seem to be able to do that directly.

/*I thought this is the correct syntax but it will generate an error*/

column cause, (N PCTN);

define cause / group;

ERROR: A GROUP variable appears above or below other report items.

/* this will run but PCTN always gives me 0*/

column cause (N PCTN);

define cause / group;

Anyone can help with this? I hope to know why the above code does not work and how to do it correctly.

Many thanks,

Peter

Accepted Solutions
Solution
‎04-10-2012 04:10 PM
SAS Super FREQ
Posts: 9,365

## Re: multiple statistics in proc report

Hi:

The comma (,) in your first COLUMN statement implies that you want to "cross" or "nest" the statistics underneath the CAUSE variable values. This is probably not what you really want to do for the simple N and PCTN based on CAUSE.

Your second PROC REPORT is correct and the percent number only needs formatting to show as you expect. By default, when PROC REPORT calculates a percent, it does NOT do a multiply by 100.  So, if you formatted your number differently (with more decimal places), you would see the numbers, like 0.0568 or something. Multiplied by 100, that would turn into 5.68%

Take a look at the code below. For N and PCTN, you do not need the comma. For other statistics, like MIN, MEAN, MAX, etc, you would need to "cross" or "nest" those statistics with a numeric variable (see #3).

cynthia

ods rtf file='c:\temp\table_pct.rtf'

startpage=no bodytitle;

proc report data=sashelp.class nowindows;

title '1 getting n and pctn with percent sign';

column sex N PCTN;

define sex / group;

define pctn / f=percent8.2;

rbreak after / summarize;

run;

proc report data=sashelp.class nowindows;

title '2 getting n and pctn without percent sign';

column sex N PCTN;

define sex / group;

define pctn / f=10.5;

rbreak after / summarize;

run;

proc report data=sashelp.class nowd;

column sex height,(min mean) weight,(median max) n pctn;

define sex / group;

define pctn / f=percent8.2;

rbreak after / summarize;

run;

ods rtf close;

All Replies
Solution
‎04-10-2012 04:10 PM
SAS Super FREQ
Posts: 9,365

## Re: multiple statistics in proc report

Hi:

The comma (,) in your first COLUMN statement implies that you want to "cross" or "nest" the statistics underneath the CAUSE variable values. This is probably not what you really want to do for the simple N and PCTN based on CAUSE.

Your second PROC REPORT is correct and the percent number only needs formatting to show as you expect. By default, when PROC REPORT calculates a percent, it does NOT do a multiply by 100.  So, if you formatted your number differently (with more decimal places), you would see the numbers, like 0.0568 or something. Multiplied by 100, that would turn into 5.68%

Take a look at the code below. For N and PCTN, you do not need the comma. For other statistics, like MIN, MEAN, MAX, etc, you would need to "cross" or "nest" those statistics with a numeric variable (see #3).

cynthia

ods rtf file='c:\temp\table_pct.rtf'

startpage=no bodytitle;

proc report data=sashelp.class nowindows;

title '1 getting n and pctn with percent sign';

column sex N PCTN;

define sex / group;

define pctn / f=percent8.2;

rbreak after / summarize;

run;

proc report data=sashelp.class nowindows;

title '2 getting n and pctn without percent sign';

column sex N PCTN;

define sex / group;

define pctn / f=10.5;

rbreak after / summarize;

run;

proc report data=sashelp.class nowd;

column sex height,(min mean) weight,(median max) n pctn;

define sex / group;

define pctn / f=percent8.2;

rbreak after / summarize;

run;

ods rtf close;

🔒 This topic is solved and locked.