BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

Hi i have a table like below 

 

data dummy;
input subjid parcat $ AVAL;
cards;
001 CA 5
001 CB .
001 CC .
002 DA 8
002 DB .
003 EA 9
003 EB .
003 EC .
003 ED .
;
run;

 

 

i want to impute the values of 5 till the end of subjid 001 , similarly for imputation of value 8 for the subjid 002 and so on. any ideas how to go about doing it by retain statement or any other smooth procedure?

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Try this

 

data Want;
   update dummy(obs=0) dummy;
   by subjid;
   output;
run;

View solution in original post

7 REPLIES 7
novinosrin
Tourmaline | Level 20

data dummy;
input subjid parcat $ AVAL;
cards;
001 CA 5
001 CB .
001 CC .
002 DA 8 
002 DB . 
003 EA 9 
003 EB . 
003 EC . 
003 ED .
;
run;

data want;
 update dummy(obs=0) dummy;
 by subjid;
 output;
run;
PeterClemmensen
Tourmaline | Level 20

Try this

 

data Want;
   update dummy(obs=0) dummy;
   by subjid;
   output;
run;
sahoositaram555
Pyrite | Level 9

Hi later i saw in the dataset shome places that it looks something like below.

data dummy;
input subjid parcat $ AVAL;
cards;
001 CA .
001 CB .
001 CC 5
002 DA .
002 DB 6
002 DB .
003 EA 9
003 EB .
003 EC 8
003 ED .
004 FA .
004 FB .
004 FC 7
004 FD .
004 FE .
;
run;
any ideas how to imput the values correctly for each subject ids?

PeterClemmensen
Tourmaline | Level 20

Try this

 

data want (drop=_AVAL);
   _AVAL = .;
   do _N_=1 by 1 until (last.subjid);
      set dummy;
      by subjid;
      if AVAL > _AVAL then _AVAL = AVAL;
   end;
   do _N_ = 1 to _N_;
      set dummy;
      AVAL = _AVAL;
      output;
   end;
run;
sahoositaram555
Pyrite | Level 9
Hi, the dataset looks blank. any ideas why? or any other method?
novinosrin
Tourmaline | Level 20

In my opinion, if you just have one non missing value, a SQL self join is very convenient and easy to maintain 

 



data dummy;
input subjid parcat $ AVAL;
cards;
001 CA .
001 CB .
001 CC 5
002 DA . 
002 DB 6
002 DB . 
003 EA 9 
003 EB . 
003 EC 8 
003 ED .
004 FA .
004 FB .
004 FC 7
004 FD .
004 FE .
;
run;

proc sql;
create table want as
select subjid,parcat,max(AVAL) as aval
from dummy
group by subjid;
quit;

 

 

 

 

sahoositaram555
Pyrite | Level 9
hi @novinosrin, thanks .it worked

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 7 replies
  • 1456 views
  • 1 like
  • 3 in conversation