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
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;
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.