previous data step iteration values are available before they are replaced in a SET statement. The following step provides the total of current observation ID with preceding observation AGE[pre] data second_data ;
last_age = age ;
set first_data ;
if id = 4 then total = last_age + id ;
else total = . ;
run ;[/pre] Perhaps I misunderstand, and you want total calculated entirely from values in the preceding observation. That is simpler[pre] data another_way ;
total = age + ID ;
set first_data ;
if id ne 4 then total = . ;
run ;[/pre]
One effect of this approach is that missing values are present before the first SET statement, and a message would be generated about missing values. If you need to avoid that, in the second demo, derive [pre] total = sum( age, ID, 0 );[/pre] and for the first [pre] if id = 4 then total = sum( last_age, id, 0 ) ;[/pre]
Does this provide what was wanted ?
PeterC