Published on :
ETL CREATION_INTERNE

Cumulative Sum Calculation

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins with a DATA step block where a new table named 'sumexample' is created. Numerical data is read from DATALINES into a 'Number' variable. The key instruction is 'CUMSUM + Number;', which uses a 'sum statement'. This statement is unique in SAS© because it implicitly initializes 'CUMSUM' to zero for the first record and retains its value between records, adding the current 'Number' value to 'CUMSUM' for each row, thereby creating a cumulative sum. The script ends with the RUN; command to execute the DATA step.
Data Analysis

Type : CREATION_INTERNE


Source data is created directly within the SAS script using the DATALINES statement. A single variable, 'Number', is defined and populated with a series of numerical values.

1 Code Block
DATA STEP Data
Explanation :
This block is a DATA step that creates a 'sumexample' dataset. It reads the 'Number' variable from internal data lines (DATALINES). The 'CUMSUM' variable is calculated using a sum statement (CUMSUM + Number;), which allows it to accumulate the sum of 'Number' values for each observation, thereby generating a cumulative sum. 'CUMSUM' is automatically initialized to zero for the first record and retains its value from one iteration to the next.
Copied!
1DATA sumexample;
2 INPUT Number;
3 CUMSUM + Number;
4 DATALINES;
51
66
710
811.1
918
105.6
111.1
12;
13RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.