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

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16

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
ballardw
Super User

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 2 replies
  • 600 views
  • 0 likes
  • 3 in conversation