Dear,
For sorting a dataset I need to populate the decod values all relavent OBS . Please help. Thank you very much
output needed;
Bodsys decod sev
blsd mild
blsd moderate
blsd severe
blsd anae
blsd anae mild
blsd anae moderate
blsd anae severe
blsd lymp
blsd lymp mild
blsd lymp moderate
blsd lymp severe
;
data one; input bodsys $4. +1 decod $4. +1 sev $8.; datalines; blsd mild blsd moderate blsd severe blsd anae blsd mild blsd moderate blsd severe blsd lymp blsd mild blsd moderate blsd severe ;
data want (drop=hold);; set one; retain hold; if not missing(decod) then hold=decod; decod=hold; run;
Art, CEO, AnalystFinder.com
Dear,
Thank you very much for the code.You code works for me for the sample data I posted. But if the bodsys values increase it is not getting the output i need.
In the below example, The decod value='lymph' is populating for next OBS where bodsys='clsd'
Output needed;
output needed;
Bodsys decod sev
blsd mild
blsd moderate
blsd severe
blsd anae
blsd anae mild
blsd anae moderate
blsd anae severe
blsd lymp
blsd lymp mild
blsd lymp moderate
blsd lymp severe
clsd mild
clsd moderate
clsd severe
clsd cnae
clsd cnae mild
clsd cnae moderate
clsd cnae severe
data one; input bodsys $4. +1 decod $4. +1 sev $8.; datalines; blsd mild blsd moderate blsd severe blsd anae blsd mild blsd moderate blsd severe blsd lymp blsd mild blsd moderate blsd severe clsd mild clsd moderate clsd severe clsd cnae blsd mild blsd moderate blsd severe ;
data want;
set one;
retain hold;
if not missing(decod) then hold=decod;
decod=hold;
run;
output getting;
Bodsys decod sev
blsd mild
blsd moderate
blsd severe
blsd anae
blsd anae mild
blsd anae moderate
blsd anae severe
blsd lymp
blsd lymp mild
blsd lymp moderate
blsd lymp severe
clsd lymp mild
clsd lymp moderate
clsd lymp severe
clsd cnae
clsd cnae mild
clsd cnae moderate
clsd cnae severe
You didn't show what you want in such a situation, but it might be:
data want (drop=hold); set one; length hold $4; by bodsys notsorted; retain hold; if first.bodsys then call missing(hold); if not missing(decod) then hold=decod; decod=hold; run;
Art, CEO, AnalystFinder.com
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.