【问题标题】:Proc tabulate - custom statisticProc tabulate - 自定义统计
【发布时间】:2014-02-25 09:52:46
【问题描述】:

假设我有以下数据集:

Category  Premium1  Premium2
A         10        20
A         15        40
B         10        15
C         20        25

使用 proc tabulate(这是一个简化的示例,我有更多的分类变量和双向表),我想为每个类别显示 Premium2 相对于 Premium1 的百分比变化。

现在我创建了一个 Premium2_over_Premium1 变量,并显示了该变量的加权平均值,其中权重为 Premium1。但这给了我一个因素,而不是百分比的变化。 例如类别 AI 将得到 ((20/10)*10 + (40/15)*15)/(10 + 15)=2.4,但我希望看到的是 2.4 - 1 = 1.4 = 140%。

这似乎是一个很简单的任务,但我找不到方法!非常感谢任何帮助。

【问题讨论】:

    标签: sas


    【解决方案1】:

    您可以在 PROC REPORT 中执行此操作,但可能无法在 PROC TABULATE 中执行此操作,至少在没有中间数据步的情况下不能。

    我没有完全按照您对百分比变化变量的要求,因为您所描述的与我对百分比变化含义的看法不符,但我认为这会为您提供您所要求的结果。如果没有,这个概念应该很容易理解。

    data have;
    input Category $ Premium1  Premium2;
    datalines;
    A         10        20
    A         15        40
    B         10        15
    C         20        25
    ;;;;
    run;
    
    proc report data=have nowd;
    columns category premium1 premium2 pctChg;
    define category/group;           *like CLASS in most other procs;
    define premium1/analysis mean;   *use for analysis, show the mean;
    define premium2/analysis mean;   *same, could include NOPRINT to hide these columns;
    define pctChg/computed format=percent9.1;  *calculated (computed) column, with a format;
    compute pctChg;                  *compute (calculate) the variable;
      pctChg = premium2.mean/premium1.mean - 1;  *to refer to analysis vars, use <var>.<statistic>;
    endcomp;
    run;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-26
      相关资源
      最近更新 更多