I want to pass SAS code in python and cannot find the save function in python.
The data is as follows:
type_id amount
1 100
1 200
1 400
2 0
1 200
1 300
2 0
1 150
What I want is when type_id = 2, the sum is equal to the negative value of the previous line. So the data will look like this:
type_id amount
1 100
1 200
1 400
2 -400
1 200
1 300
2 -300
1 150
SAS Code:
data B;
set A;
retain tempvar 0;
if type_id = 2
then amount = tempvar;
else tempvar = -amount;
drop tempvar;
run;
Does anyone have an idea on how to do this in python? Thank!
source
share