所以这段代码继续返回关于if语句的符号的错误,当我删除它们时,它运行到完成,但它拒绝打印/识别我的格式代码。这是我的新鲜事,即将把我的电脑扔出窗外,所以如果一个更训练有素的眼睛能看一眼,那就太棒了。
Proc Format;
Value $Gender '1'='Male'
'2'='Female';
Value $STATUS '1'='Yes'
'0'='No';
run;
data Myocard;
Infile '/folders/myfolders/sasuser.v94/Data for Classes 3 to 6/MI.dat';
Input ID $1-3
Gender $4
BMI 5-8
Age 9-10
DM $11
HTN $12
MI $13
PACKYR 14-15;
Format Gender $SexFMT. HTN DM MI $STATUS.;
If BMI 18.0-25.0 ='Normal';
If BMI 25.1-30.0 ='Overweight';
If BMI > 30.0 ='Obese';
If PACKYR 0 code 0;
If PACKYR > 0 code 1;
run;
proc print data= myocard label;
Label ID ='Subject Identifier'
BMI ='Body Mass Index'
DM ='Diabetes Mellitus Status'
HTN ='Hypertension'
MI ='Myocardial Infarction'
PACKYR ='Packs Smoked Per Day Per Year';
Format Gender $SexFMT. HTN DM MI $STATUS.;
run; 发布于 2021-02-25 16:57:52
我想不出你编写的语句能在哪种语言中工作。
If BMI 18.0-25.0 ='Normal';
If BMI 25.1-30.0 ='Overweight';
If BMI > 30.0 ='Obese';
If PACKYR 0 code 0;
If PACKYR > 0 code 1;您似乎是在将某个范围中的值映射到一个类别值。
您可以使用Proc FORMAT定义在Proc PRINT中使用的自定义格式
Proc FORMAT;
value BMI
18 - 25 = 'Normal'
25 - 30 = 'Overweight'
30 - high = 'Obese'
;
value packyr_code
0 = '0'
0-high = '1'
;相反,如果您想要一个新变量,可以考虑使用SELECT语句和IF/THEN/ELSE语句。
data myocard;
...
select;
when (18 < bmi < 25) obesity_class = 'Normal';
when (25 <= bmi < 30) obesity_class = 'Overweight'
when (30 < bmi) obesity_class = 'Obese'
otherwise obesity_class = cats('bmi:',bmi);
end;
if packyr = 0 then code = 0;
else if packyr > 0 then code = 1;
else code = -1;
run;发布于 2021-02-26 00:56:22
您的IF语句在语法方面是不正确的。
未将新值分配给新的variable
这段代码:
If BMI 18.0-25.0 ='Normal';
If BMI 25.1-30.0 ='Overweight';
If BMI > 30.0 ='Obese';应该是:
If 18.0<BMI<=25 then BMI_Category ='Normal';
else If 25.1<=BMI<=30.0 then BMI_Category ='Overweight';
else If BMI > 30.0 then BMI_Category='Obese';
If PACKYR = 0 then code_category = 0;
else PACKYR > 0 then code_category = 1; 或者将格式与PUT语句一起使用
BMI_Category = put(BMI, BMI.);
Code_category = put(packyr, packyr_code.);https://stackoverflow.com/questions/66362015
复制相似问题