data T;
input ID L M EXP;
Datalines;
1 1 100 10
1 2 100 20
1 2 100 20
1 3 100 30
2 1 50 10
2 1 50 20
2 2 50 60
;
Hi, based on this dataset I want to create a new dataset with an extra column (WANTED) which includes the following steps:
1. All calculations are per group ID
2. For each first ID occurrence, the value WANTED is equal to the value in Col EXP
3. For the second row and so on, the formula is IF L=1 then =EXP Else if (cumulative sum of previous values WANTED<MV) then MV-LAG(EXP) ELSE 0
Finally the WANTED column should have the following values
10
90
0
0
10
20
30
Thank you in advance for your help.
... View more