【问题标题】:dividing a numeric variable in sas在 sas 中划分数字变量
【发布时间】:2017-04-24 10:53:20
【问题描述】:

假设我有一个名为 data 的数据和一个变量 age 我正在寻找一种方法将代表年龄的变量划分为一个显示年龄组含义的新变量,18-21,21-24 等等。 我知道如何使用 proc sql 和 if 来完成,但我知道使用 round 函数有一种有效的方法。

有谁知道如何使用round来划分数值变量?

谢谢。

【问题讨论】:

  • 您应该尝试自己做一些尝试,以成为一个有效的 SO 问题。您是否还考虑过创建一种格式来显示数据?这样你就不需要新变量了。

标签: sas


【解决方案1】:

方法 1: 使用 If/Else
方法 2: 使用 Proc 格式
我已经分享了 method2 的代码,因为您已经知道 method1

proc format;
value age
low - 9 = '0 - 9'  
10 - 19 = '10 - 19'
20 - 29 = '20 - 29'
30 - 39 = '30 - 39'
40 - 49 = '40 - 49'
50 - 59 = '50 - 59'
60 - high = '60 +++'
;
run;


/**1) If you just want to look at age in bucket form         **/
    data abc;
    set abc;
    format age age.;
    run;    

/**2) If you want to create another variable(say age_bucket)  **/
    data abc;
    set abc;
    age_bucket = put(age,age.);
    run;

如有任何疑问,请告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-04
    • 1970-01-01
    • 2016-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多