SAS: Calculating sum within each group -


this question has answer here:

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

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -