BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

I want to merge data set aaa and data set bbb  .

I want to check if any value of column Team in data set aaa exists in data set bbb.

The way of checking is:

step1- delete blanks (before,between and after ) in column Team in data seta aaa 

step2- delete blanks (before,between and after ) in column Team in data seta bbb

Step3- check if calculated  Team column in data set aaa  exists in data set b

What is the way to do it please?

Data aaa;
input  team $ 1-20;
cards;
London
Tel aviv
Berlin
Warsaw
Tokyo
;
Run;

Data bbb;
input  team $ 1-20;
cards;
Inc London city
Telaviv
Western Berlin 
;
Run;

 
data aaa_new;
set aaa;
team_new=COMPRESS(team);
drop team;
rename team_new=team;
run;


data bbb_new;
set bbb;
team_new=COMPRESS(team);
drop team;
rename team_new=team;
run;

 

 

 

5 REPLIES 5
ChrisNZ
Tourmaline | Level 20

Should  Berlin  match  Western Berlin  ?

Ronein
Meteorite | Level 14

Yes, because name Berlin included in name West Berlin

 

 

andreas_lds
Jade | Level 19

Please use the search-function, partial matching has been discussed many times, you should be able to adapt one of the solutions.

gamotte
Rhodochrosite | Level 12

Hello,

 

You can try as follows :

 

Data aaa;
input  team $ 1-20;
cards;
London
Tel aviv
Berlin
Warsaw
Tokyo
;
Run;

Data bbb;
input  team $ 1-20;
cards;
Inc London city
Telaviv
Western Berlin 
;
Run;

proc sql noprint;
  CREATE TABLE want AS
  SELECT a.team, b.team AS team_b
  FROM aaa a
  LEFT JOIN bbb b
  ON compress(b.team) CONTAINS compress(a.team)
  ;
quit;
ChrisNZ
Tourmaline | Level 20

Or, to have more matches:

 

proc sql ;
  CREATE TABLE want AS
  SELECT unique a.team, b.team AS team_b
  FROM      aaa a
  LEFT JOIN bbb b
  ON find(compress(b.team), compress(a.team), 'i')
   | find(compress(a.team), compress(b.team), 'i') ;
quit;

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 795 views
  • 2 likes
  • 4 in conversation