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

sas
data_wrangling

#1

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.


#2

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


#3

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.

Regards,


#4

@Armaan

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;
Datalines;
1 2
2 4
3 7
4 10
5 11
;
Run;

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

,Imran