假设我有类似下面的数据集。我需要输出哪个学生在每个科目中得到高分并且学生姓名应该在输出中?
input student$ phy math chem eng;
datalines;
raju 89 56 37 99
raki 80 90 76 45
rani 56 65 88 43
ramya 67 98 70 67
;
使用任何方法(datasep,proc sql或其他过程)
答案 0 :(得分:0)
使用临时数组自动保留的事实:
data chapions (keep=student high_score);
set scores end=last;
array score {} phy math chem eng;
array high {4} _temporary_ ;
array champ {4} $ _temporary_ ;
if _N_ eq 1 then do dicipline = 1 to 4;
high(dicipline) = score(dicipline);
champ(dicipline) = student;
end;
else do dicipline = 1 to 4;
if high(dicipline) lt score(dicipline) then do;
high(dicipline) = score(dicipline);
champ(dicipline) = student;
end;
end;
if last then do dicipline = 1 to 4;
high_score = high(dicipline);
student = champ(dicipline) ;
output;
end;
run;
未经测试的草稿,在通过正确描述所需输出来改进问题时进行改进