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

rather than sentences, can you give a good representative sample of what you have plz

Reeza
Super User
Since this was answered in your other thread, I'm going to merge them.
FreelanceReinh
Jade | Level 19

Minor variant of @novinosrin's solution (sorting the names rather than the letters contained in the names) and more test data:

data have;
input name $50.;
cards;
Sylvie Elpers
Lissy Pleever
Elvis Presley
Lily Spreeves
Presley Elvis
;

data t;
set have;
array t(5) $25 _temporary_;
length w $50;
call missing(of t(*));
n=compbl(upcase(name));
do _n_=1 to countw(n,' ');
  t(_n_)=scan(n,_n_,' ');
end;
call sortc(of t(*));
w=catx(' ', of t(*));
run;

proc sort data=t out=want(drop=w n) nodupkey;
by w;
run; 
goravnet
Calcite | Level 5

Hello..

 

I am pretty new to SAS.. I found solution good for most of cases but it will fail for the scenarios where two different names have same set of characters like mentioned below..

 

Example:
Raam Rahim
Ram Rahima
Rahim Raam
Rama Rahim

 

Output should be 3 names but code is generating just one output so i don't think so we can use character sorting to compare and probably we need to compare word by word.

jfaruqui
Obsidian | Level 7
As a matter of fact this solution is more relevant because, as you rightly demonstrated above, different unique names can still contain the same letters .. if we sort by letters then the entire dataset will be eliminated except 1 name !! So yes, this solution is more robust
goravnet
Calcite | Level 5
But I am not able to come up with solution though.. I can find duplicate values but not final dataset
jfaruqui
Obsidian | Level 7
check the solution given above by FreelanceReinhard ... sorting by words not by letters
goravnet
Calcite | Level 5

After some analysis and reuse of the code mentioned in solution i am able to come up with solution to cater different name similar character issue.. Not so elegant but it works so far..

 

data One;
input Name $50.;
cards;
Raam Rahim
Ram Rahima
Rahim Raam
Rama Rahim
;
run;


data Two;
set One;
reversename = upcase(scan(name,2)) || ' ' || upcase(scan(name,1));
Uname = upcase(name);
run;

proc sql;
create table Three as
Select A.Name from Two A, Two B where A.UName = B.reversename;
quit;


data t;
set three;
array t(50) $1 _temporary_;
call missing(of t(*));
n=compress(upcase(name));
do _n_=1 to length(n);
t(_n_)=char(n,_n_);
end;
call sortc(of t(*));
w=cats(of t(*));
run;


proc sort data=t out=want(drop=w n) nodupkey;
by w;
run;

proc sql;
select Name FROM One except (select name from want );
quit;

 

 

novinosrin
Tourmaline | Level 20

use the word by word solutuon in the same thread. It's there as suggested by @jfaruqui

 

@jfaruqui  Please mark @FreelanceReinh 's solution as correct to avoid confusion . thanks

novinosrin
Tourmaline | Level 20

Programming is not always necessarily years of experience, rather the ability to grasp and think fast in my opinion. Being new is never a constraint and I'm relatively new 

 

 

data One;
input Name $50.;
cards;
Raam Rahim
Ram Rahima
Rahim Raam
Rama Rahim
;
run;
data _null_;
if _n_=1 then do;
   declare hash H () ;
   h.definekey  ("name1","name2") ;
   h.definedata ("name") ;
   h.definedone () ; 
   end;
set one end=lr;
name1=scan(upcase(name),1,' ');
name2=scan(upcase(name),2,' ');
rc=h.check();
rc1=h.check(key:name2,key:name1);
if rc1 ne 0 and rc ne 0 then rc2=h.add();
if lr then h.output(dataset:'want');
run;

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 24 replies
  • 1790 views
  • 7 likes
  • 6 in conversation