A little announcement. A lot to explore.

Happy learning!

Explore lessons, including SAS & R programs and practice data.

Search lessons

Type at least 3 characters to see matching lessons.

Open SAS ↗Open R ↗
← SASnRCumulative Sum, Mean, and Product

Introduction

  • Running totals show up everywhere — cumulative exposure, cumulative score, running product for compounding, rolling average for trends.
  • A cumulative function takes a vector and returns a vector of the same length where each element is the accumulated result up to that point.
  • SAS reaches for RETAIN inside a DATA step, together with sum statements (cum_sum + score;) for addition and explicit multiplication for products.
  • R has built-ins: cumsum() for running sum, cumprod() for running product, and derived forms for running average.
  • Running average is a quotient of the running sum and the running row count — both SAS and R build it the same way.
  • This lesson computes running sum, product, and average on a five-row score vector so every step is easy to verify.

Cumulative Sum, Mean, and Product