Hot to create a variable for cumulative values using Retain statement in SAS?



HI im stuck @ this program.
id actual retain
1 5 (missing value with . )
2 13 18
3 15 33
4 2 35

my last variable “retain” shud have cumulative values with regard to “actual” variable, but the first obs value in retain variable shud be missing and remaining values shud be cumulative addition values.


You want to create this dataset? I am not clear what you have and what you want to achieve.


ok here i have uploaded the file,
i want my dataset to be like this, here the last variable B is the result of retain statement performed on A variable for cumulative addition.
my first obs value should be missing (.) and the remaining values shud be the cumulative addition of the A variable.

hope u got the Question.




Below are the SAS statements that will solve your problem although I am not clear with the requirement (Business Case).

Data Src_Data;
Input ID A;
1 2
2 4
3 7
4 10
5 11

Data Final (Drop = B Cnt);
Set Src_Data;
if cnt=0 then C=.;
Else C=B;