BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

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
;
3 REPLIES 3
art297
Opal | Level 21
data want (drop=hold);;
  set one;
  retain hold;
  if not missing(decod) then hold=decod;
  decod=hold;
run;

Art, CEO, AnalystFinder.com

 

knveraraju91
Barite | Level 11

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

art297
Opal | Level 21

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

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1035 views
  • 3 likes
  • 2 in conversation