我使用的文件包含三组参与者,他们属于三个体重类别之一:肥胖,体重正常和成功减肥维护者。值得庆幸的是,他们的身份证号码与他们所在的群体相对应。肥胖为500s和800s,NW为600s,SWLM为700。
这是我正在使用的代码:
data dummy_2;
set dummy;
if ptID = 'group' then group=1;
if ptID = 102-545 or ID= 800-810 then group =0;
if ptID = 600-632 then group=1;
if ptID = 700-721 then group=2;
if ptID = 99999 or 99998 then group=.;
run;
代码本身没有错误。
注意:从数据集WORK.DUMMY_2中读取了103个观察值。 注意:使用PROCEDURE PRINT(总处理时间): 实时0.01秒 cpu时间0.01秒
但是当我对新组变量进行快速打印时,它在结果选项卡中显示的数据给了我一列bmi数据,除了一切都是(。)
文件中没有其他组变量(我搜索我保存的excel版本)
然后我将变量名称更改为条件,认为名称组可能与命令太相似。 内联图片1
它现在在列的顶部显示条件而不是组,但我不确定它为什么会显示这些图表。
data dummy_2;
set dummy;
if ptID = 'condition' then condition=0;
if ptID = 102-545 or ptID= 800-810 then condition =0;
if ptID = 600-632 then condition=1;
if ptID = 700-721 then condition=2;
if ptID = 99999 or 99998 then condition=.;
run;
proc print;
var condition;
run;
有什么想法吗?
谢谢!
答案 0 :(得分:2)
if ptID = 600-632 then condition=1;
您认为这是什么?
我会告诉你一个线索。它与此完全相同。
if ptID = -32 then condition=1;
我猜这不是你所希望的。您需要使用in
运算符。
if ptID in (600:632) then condition=1;
我假设ptID
是数字。如果它是个性,那么你不能完全做到这一点,你应该让我们知道。
我会注意到,进行此类分组的最佳方法是使用以下格式:
proc format;
value condGroupF
102-545 = '0'
600-632 = '1'
700-721 = '2'
800-810 = '0'
99998-99999 = ' '
other= ' '
;
quit;
然后
data dummy_2;
set dummy;
condition = put(ptID,CondGroupF.);
run;
请注意,在格式中,“破折号”样式是正确的,它在数据步骤中不是。