11-14-2016 03:47 PM - edited 11-14-2016 03:49 PM
Q. Write the data step that creates a variable that should have the number of animals that are 200 kg or heavier than 200 kg.
My Ans - This code is not giving me desired results. Any modification on what is the issue ASAP will be of great help.
input animals $ weight;
data sum; set animal_weight;
do i = 1 to 16;
if animl(i) >= 200 then count + animl(i);
proc print data=sum;
11-14-2016 04:13 PM
Revise the notion of implicit looping in the data step. This would work:
data over200; set animal_weight end=done; count + (weight >= 200); if done then output; keep count; run;
Explain the role of each statement to deserve a good mark.
11-14-2016 04:16 PM - edited 11-14-2016 04:19 PM
Your first step creates a table where each animal holds one row;
You cannot use array to deal with different rows;
You can use an array only to deal with a set of variables in the same row.
Next code will do what you ask:
set animal_weight end=eof;
retain count sum_weight 0;
if weight GE 200 then do;
sum_weight = sum(of sum_weight , weight);
if eof then put sum_weight= count=;