【问题标题】:2x2 table with frequency and overall percentage in SAS - proc tabulate?SAS中频率和总体百分比的2x2表 - proc制表?
【发布时间】:2017-10-13 20:23:44
【问题描述】:

我有一组前后分数,其值可以是 1 或 2,例如:
预发布
1 2
1 1
2 2
2 1
1 2
2 1
等等

我需要创建一个列出频率的 2x2 表,仅在总行/列中显示百分比:

           1           2       Total
1         14          60      74 / 30%
2         38          12      50 / 20%
Total   52 / 21%    72 / 29%    248

不需要在 n 和百分比之间用​​ / 专门格式化,它们可以在不同的行上。我只需要确保总百分比(没有累积百分比)在表中。

我认为我应该使用 proc tabulate 来获得这个,但我是 SAS 新手,无法弄清楚。任何帮助将不胜感激。

我试过的代码:

proc tabulate data=.bilirubin order=data; 
   class pre ; 
   var post ; 
   table pre , post*( n colpctsum); 
run;

【问题讨论】:

  • 到目前为止,您在PROC TABULATE 中尝试过什么?您当然是正确的,在那里可以做到。
  • 我唯一能运行的是这个,但它没有给我一个 2x2 的表格,也没有给我底行的百分比:proc tabulate data=.bilirubin order=data;课前;变种帖子;表前,后*(n colpctsum);运行;
  • 改用 PROC FREQ?您可以使用 OUTPCT 控制报告的百分比
  • 我也尝试了很多变体,但我无法弄清楚如何仅获得总数的百分比。你知道怎么做吗?

标签: sas


【解决方案1】:

您可以制作自己的报告。例如,您可以使用 PROC Summary 来获取频率。添加一个数据步骤来计算百分比并使用您要显示的文本生成一个字符变量。然后使用 PROC REPORT 来显示它。

proc summary data=have ;
  class pre post ;
  output out=summary ;
run;
proc format ;
  value total .='Total (%)';
run;
data results ;
  set summary ;
  length display $20 ;
  if _type_=0 then n=_freq_;
  retain n;
  if _type_ in (0,3) then display = put(_freq_,comma9.);
  else display = catx(' ',put(_freq_,comma9.),cats('(',put(_freq_/n,percent8.2),')'));
run;
proc report  missing data=results ;
  column pre display,post n ;
  define pre / group ;
  define post / across ;
  define n / noprint ;
  define display / display ' ';
  format pre post total.;
run; 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-14
    • 2020-10-17
    • 2014-02-23
    • 2011-04-17
    • 1970-01-01
    • 2019-09-29
    相关资源
    最近更新 更多