【发布时间】:2016-10-26 12:55:38
【问题描述】:
我有以下数据集。我想为每个学生创建一个 Flag(Score>50) 列,以获取分数大于 50 的科目数。 我知道一种方法,方法是为每个主题创建一个使用 if 条件的标志,然后添加它们,但只是好奇在 SAS 中是否有更好的方法来做到这一点?谢谢!!
Student_ID,Physics,Maths,Social,English,Chemistry,Flag(Score>50)
1011,90,90,60,30,20,3
1012,60,90,30,40,40,2
1013,30,10,80,70,50,2
1014,70,10,40,90,90,3
data score1;
set score;
if Physics > 50 then Phy_flag = 1;
if Maths > 50 then Math_flag=1;
if Social > 50 then Social_flag=1;
if English > 50 then Eng_flag=1;
if Chemistry > 50 then Chem_flag=1;
Flag_Score_50 = sum(Phy_flag,Math_flag,Social_flag,Eng_flag,Chem_flag);
run;
这就是我所做的,但我在其他数据集中有太多变量,我不想多次写这些 if 条件。发送
【问题讨论】:
标签: count sas conditional-statements