@RDzh wrote:
Thanks, Tom This kindaaa does what I'm trying to get to.
As to being "much more specific", I literally say what I'd like help with: "all rows of a second group to be a fraction of the corresponding values in last row of the previous group". I don't say anything else because I don't want anything else.
So that is much clearer than your first attempt. But it does not cover what values you want for the first group.
You will need NEW variables to be able to do this. You can always add some drop and/or rename statements to make them use the original names.
For simplicity let's just do it for ONE variable first.
Also let's assume you want the new variable to be MISSING on the first group.
data want;
set have;
by group;
retain new1;
output;
if last.group then new1 = .95 * val1 ;
run;
Result
Obs Group val1 new1
1 1 5.00 .
2 1 4.00 .
3 1 7.00 .
4 2 6.65 6.65
5 2 5.00 6.65
To extend it to multiple variables just add arrays.
data want;
set have;
by group;
array old val1-val2;
array new new1-new2;
retain new1-new2;
output;
if last.group then do over old;
new = old * 0.95;
end;
run;
If you want non-missing values for the first group then explain what values you want.
... View more