You can not execute the LAG function conditionally. The LAG function has to be executed for every observation. See the sample below with the modfied logic. You can make use of BY group processing and the FIRST. functionality. data have;
infile cards dlm=",";
input
count_cluster
Max_salary
;
cards;
1, 56768
1,70741
2,49957
3,50000
4,34360
4,49790
4,53220
;
data want;
set have;
by count_cluster;
_prev_salary = lag1(max_salary);
if first.count_cluster = 0 then do;
Max_Salary_previous_grade = _prev_salary;
end;
drop _prev_salary;
run; Bruno
... View more