Filling in missing values

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 121
Accepted Solution

Filling in missing values

My data currently looks like this:

 

LoanId       Product_Code

32456         Fixed-30

32456         Fixed-30

32456

32456    

75639         Fixed-15

75639

75639

84732         Adjustable-Rate

84732         Adjustable-Rate

84732

84732

 

I need to fill in the blanks in the product_code variable so that my records have no blanks; please not that product_code is a character variable. Utlimately, I need my data to look like this.

 

LoanId       Product_Code

32456           Fixed-30

32456           Fixed-30

32456           Fixed-30

32456           Fixed-30

75639           Fixed-15

75639           Fixed-15

75639           Fixed-15

84732           Adjustable-Rate

84732           Adjustable-Rate

84732           Adjustable-Rate

84732           Adjustable-Rate

 

Any help would be extremely appreciated; thanks in advance.

 


Accepted Solutions
Solution
‎09-25-2015 06:23 AM
Super User
Posts: 11,105

Re: Filling in missing values

If you don't want to sort the data:

data want;
   set have;
   if _n_=1 then lprod=product_code;
   retain lprod;
   if missing(x) then product_code= lprod;
   else lprod=product_code;
   drop lprod;
run;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,137

Re: Filling in missing values

[ Edited ]

I believe first. will be correct

Proc sort data=have;
by LoanId Product_Code;
run;

data want(rename=(product_code_=product_code));
set have;
by LoanId Product_Code;
retain product_code_;
if first.product_code then product_code_='';
if product_code ne '' then product_code_=product_code;
drop product_code;
run;

 

Thanks,

Jag

 

Thanks,
Jag
Solution
‎09-25-2015 06:23 AM
Super User
Posts: 11,105

Re: Filling in missing values

If you don't want to sort the data:

data want;
   set have;
   if _n_=1 then lprod=product_code;
   retain lprod;
   if missing(x) then product_code= lprod;
   else lprod=product_code;
   drop lprod;
run;
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 330 views
  • 0 likes
  • 3 in conversation