【问题标题】:How to compute survival rates in SAS Guide?如何在 SAS Guide 中计算生存率?
【发布时间】:2019-09-02 08:58:50
【问题描述】:

我想计算一个公式,即生存率,在我的例子中,我将其称为 Z 变量。我正在考虑使用宏,但我找不到简单的方法来做到这一点。在下表中,我有一个假装的示例。

提议是通过id进行Z计算。

所以 X(i,j) 变量是 id_time j 中 id i 的默认概率,其中 i = 1,..,3 和 j = 1,..,4

Y(i,j) = 1 - x(i,j) 总是。

Z(i,j) = Y(i,j-1) * Z(i,j-1) 当 j = 1 时除外,其中 Z(i,1) = 1 = 100%。

如果你们需要更多详细信息,请告诉我。

这是一个例子:

id  id_time    x       y    z
1   1      0,010    0,990   1
1   2      0,015    0,985   0,990
1   3      0,020    0,980   0,975
1   4      0,025    0,975   0,956
2   1      0,010    0,990   1
2   2      0,015    0,985   0,990
2   3      0,020    0,980   0,975
2   4      0,020    0,980   0,956
3   1      0,005    0,995   1
3   2      0,010    0,990   0,995
3   3      0,020    0,980   0,985
3   4      0,030    0,970   0,965

【问题讨论】:

    标签: macros sas


    【解决方案1】:

    我按照你的公式来做。

    data test;
        format x y 12.3;
        input id: id_time: x: comma9. y: comma9.;
        x = x * 0.001;
        y = y * 0.001;
        cards;
        1   1      0,010    0,990
        1   2      0,015    0,985
        1   3      0,020    0,980
        1   4      0,025    0,975
        2   1      0,010    0,990
        2   2      0,015    0,985
        2   3      0,020    0,980
        2   4      0,020    0,980
        3   1      0,005    0,995
        3   2      0,010    0,990
        3   3      0,020    0,980
        3   4      0,030    0,970
    ;
    run;
    
    data _null_;
        retain Z;
        set test;
        by id notsorted;
    
        LagY = Lag(y);
        if first.id then LagY = .;
        if first.id then Z = 1;
        if not first.id then Z = round(LagY * Z,0.001);
        put (id id_time x y z)(=);
    run;
    

    输出:

    id=1 id_time=1 x=0.010 y=0.990 Z=1
    id=1 id_time=2 x=0.015 y=0.985 Z=0.99
    id=1 id_time=3 x=0.020 y=0.980 Z=0.975
    id=1 id_time=4 x=0.025 y=0.975 Z=0.956
    id=2 id_time=1 x=0.010 y=0.990 Z=1
    id=2 id_time=2 x=0.015 y=0.985 Z=0.99
    id=2 id_time=3 x=0.020 y=0.980 Z=0.975
    id=2 id_time=4 x=0.020 y=0.980 Z=0.956
    id=3 id_time=1 x=0.005 y=0.995 Z=1
    id=3 id_time=2 x=0.010 y=0.990 Z=0.995
    id=3 id_time=3 x=0.020 y=0.980 Z=0.985
    id=3 id_time=4 x=0.030 y=0.970 Z=0.965
    

    【讨论】:

    • 为什么 Z 响应与预期不同?
    • @Rhythm 你的意思是在哪里?
    猜你喜欢
    • 1970-01-01
    • 2022-09-27
    • 2017-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-17
    相关资源
    最近更新 更多