The SAS Output Delivery System and reporting techniques

multiple statistics in proc report

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

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*/

proc report data=mouse nowindows headline;

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*/

proc report data=mouse nowindows headline;

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: 8,743

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;

title '3 asking for statistics';

  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;

View solution in original post


All Replies
Solution
‎04-10-2012 04:10 PM
SAS Super FREQ
Posts: 8,743

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;

title '3 asking for statistics';

  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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 1536 views
  • 1 like
  • 2 in conversation