/* One of the things SAS is quirky about is how you are forced to take a different appraoch in summing a column of numbers as opposed to other programming languages. This is because SAS automatically reads the rows or observations for you rather than you providing it with the code to do so like you would in Visual Basic and other languages. In order to sum a column of numbers, you need to use the RETAIN statement */ *First we read in a test data set for you; data mydata; input Y VAR1 VAR2 VAR3; cards; 1 10 33 4 0 20 21 3 1 30 59 2 1 20 76 1 0 . 24 3 0 20 22 2 1 10 28 2 1 10 49 2 0 30 76 2 1 20 59 2 ; *For illustrative purposes, we can read this data into another dataset; * and then do the sums using RETAIN; data test; set mydata; retain mysum 0; /*put the sum variable after the retain variable and initialize to zero*/ *You always have to account for "missing values(.)" in SAS, otherwise, all your answers; * will turn out to be missing (".").; if var1^=. then mysum=var1+mysum; run; Title Cumulative Sum of VAR1; proc print data=test;run;