SAS: Calculating sum within each group -
this question has answer here:
- sas difference between sum , +? 2 answers
data cumsum; set temp; group; if first.group sum = 0; sum + x if last.group output; run;
the code above calculates sum within each group, if change sum + x
sum = sum + x
, result not correct. explain difference between sum + x
, sum = sum + x
?
the sum+x;
notation has implicit retain
statement added when code runs.
if use sum = sum + x;
notation, must explicitly state retain statement manually. ie.
data cumsum; set temp; group; retain sum 0; if first.group sum = 0; sum = sum + x if last.group output; run;
Comments
Post a Comment