An efficient way to Copying values in subsequent records - SAS -
i have dataset grouped category variables in source data. example:
bar | foo1 | foo2 | foo3 bar2 | foo4 | foo5 | foo6
after import source data, above result in first variable (parent) being populated on record 1 not #2 , #3. copy parent variable's value record 2 , 3. output more this:
bar | foo1 bar | foo2 bar | foo3 bar2 | foo4 bar2 | foo5 bar2 | foo6
i tried using "lag" function, doesn't seem working. here code:
if parent ~= "" do; parent = parent; end; else do; parent = lag(parent); end;
you can retain non-missing value , apply missing values, e.g.
data want ; set have ; length last $10. ; retain last '' ; if not missing(parent) last = parent ; else parent = last ; drop last ; run ;
Comments
Post a Comment