Please provide actual example data and expected results.
Are those supposed to be character strings? So you should be able to use BY group processing and LAG().
data have;
input existing $ @@;
cards;
A A A A A
B B B B B B B
C C C
D D
;
data want;
set have;
by existing notsorted;
lag_existing=lag(existing);
length new_variable $10 ;
if first.existing then new_variable=catx('+',new_variable,lag_existing);
retain new_variable ;
drop lag_existing;
run;
If those are supposed to be numbers in looks like a running SUM.
data have;
input existing @@;
cards;
2 2 2 2 2
1 1 1 1 1 1 1
3 3 3
5 5
;
data want;
set have;
by existing notsorted;
lag_existing=lag(existing);
length new_variable 8 ;
if first.existing then new_variable=sum(new_variable,lag_existing);
retain new_variable ;
drop lag_existing;
run;
... View more