首页 > 解决方案 > 在 SAS 中创建年龄组变量

问题描述

我需要帮助创建这个年龄组变量。在我的数据中,年龄被测量到小数点后 9 位。我可以决定我刚刚选择的四分位数的类别。但我不断收到这些错误...

“错误 388-185:需要算术运算符。错误 200-322:符号无法识别,将被忽略。”

我已经尝试四舍五入并将 le 更改为 <= 但它仍然给出相同的错误...... :(

data sta310.hw4;
   set sta310.gbcshort;
   age_cat=.;
   if age le 41.950498302 then age_cat = 1;
   if age > 41.950498302 and le 49.764538386 then age_cat=2;
   if age > 49.764538386 and le 56.696966378 then age_cat=3;
   if age > 56.696966378 then age_cat=4;
run;

标签: sas

解决方案


这东西最好使用 proc 格式。您在和算术运算符之后缺少变量名。你也不需要 age_cat = 。在一开始的时候。请在您的算术运算符之后和之前添加您的年龄变量,如下所示

 data sta310.hw4;
 set sta310.gbcshort;
 age_cat=.;
  if age le 41.950498302 then age_cat = 1;
  if age > 41.950498302 and age le 49.764538386 then age_cat=2;
  if age > 49.764538386 and age le 56.696966378 then age_cat=3;
   if age > 56.696966378 then age_cat=4;
 run;

推荐阅读