· Step 1:
o Create a temporary data set, cleandata36.
o In this data set, convert all groupvalue to upper case.
o Then keep only observationswith group equal to ‘A’ or ‘B’.
· Step 2:
o Determine the MEDIAN value forthe Kilograms variable for each group (A,B) in the cleandata36data set. Round MEDIAN to the nearest whole number.
· Step 3:
o Create results.output36from cleandata36.
o Ensure that all values forvariable Kilograms are between 40 and 200, inclusively.
o If the value is missing or out of range, replace the value with theMEDIAN Kilograms value for the respective group (A,B) calculatedin step 2.
Run the program and use the results to answer the next 3 questions.
三个问题分别是:How many observations are in results.output36?What is the MEAN Kilograms value for group=’A’ in the results.output36 data set? What is the MEAN Kilograms value for group=’B’ in the results.output36data set?
我第一个问题答案是4897,回答错了,正确答案是4992。但是后两个问题都回答正确。对比答案发现,问题可能是出现在step1的赋值上。
我的代码如下:
data cleandata360;
set cert.input36;
group=upcase(group);
where group in ("A" "B"); /*官方答案没有对group转化为大写,而是直接 if upcase(group) in ('A','B');其它步骤一样*/
run;
另外看到一种答案也得出4992的结果,代码如下:
data cleandata36a (drop =group);
set cert.input36;
group1=upcase(group);
run;
data new123;
set cleandata36a;
where group1 in ('A' 'B');
rename group1=group;
run;
求问 我的写法为什么会少观测值呢?先谢谢各位大佬了