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

Hi

 

I have data which have merchant names but mispelled texts. which is becoming hard while joining this table with other table on basis of merchant name. im trying to replace the text with first row in the group. if first 10 characters are same.

 

Data Have;
input merchant_name $20.;
cards;
future retail pvt. ltd.
future retail limited
future retail ltd
osborne corporation
osborne corp ltd
;


run;

 

desired output should be like

future retail pvt. ltd.
future retail pvt. ltd.
future retail pvt. ltd.
osborne corporation
osborne corporation

thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Like this?

data HAVE;
input MERCHANT_NAME $40.;
cards;
future retail pvt. ltd.
future retail limited
future retail ltd
osborne corporation
osborne corp ltd
run;
data WANT;
  set HAVE;
  length PREV $40;
  retain PREV;
  if MERCHANT_NAME =: substr(PREV,1,10) then MERCHANT_NAME=PREV;
  else PREV=MERCHANT_NAME;
run;

 

MERCHANT_NAME
future retail pvt. ltd.
future retail pvt. ltd.
future retail pvt. ltd.
osborne corporation
osborne corporation

View solution in original post

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

Like this?

data HAVE;
input MERCHANT_NAME $40.;
cards;
future retail pvt. ltd.
future retail limited
future retail ltd
osborne corporation
osborne corp ltd
run;
data WANT;
  set HAVE;
  length PREV $40;
  retain PREV;
  if MERCHANT_NAME =: substr(PREV,1,10) then MERCHANT_NAME=PREV;
  else PREV=MERCHANT_NAME;
run;

 

MERCHANT_NAME
future retail pvt. ltd.
future retail pvt. ltd.
future retail pvt. ltd.
osborne corporation
osborne corporation
singhsahab
Lapis Lazuli | Level 10
hi .


DATA NEW_HAVE1 (DROP=merchant_name RENAME=(PREV_VALUE=NEW_VALUE));
SET HAVE;
LENGTH PREV_VALUE $50;
RETAIN PREV_VALUE;
IF merchant_name =: SUBSTR(PREV_VALUE,1,10) THEN merchant_name=PREV_VALUE;
ELSE PREV_VALUE=merchant_name;
RUN;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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