I have a dataset that is grouped by category variables in the source data. For example:
Bar | Foo1
| Foo2
| Foo3
Bar2 | Foo4
| Foo5
| Fo
The lag function returns the last value that was passed to it when it was called, not the value that was last output.
You could do something like the following:
data want;
set have;
length last_parent $256;
retain last_parent;
if parent = "" then parent = last_parent;
else last_parent = parent;
drop last_parent;
run;
You would need to set the length of last_parent to the same length as parent to make sure nothing gets cut off.