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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 752 views
  • 1 like
  • 3 in conversation