rather than sentences, can you give a good representative sample of what you have plz
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;
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.
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;
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
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.