BookmarkSubscribeRSS Feed
squeakums
Calcite | Level 5

I am fairly new to SAS and I have 2 queries that I am trying to merge together and I'm joining by a full outer join. The names are almost the same except 1 set of data has additional space and parentheses next to the name. So, the code is not finding all of the names:

How would I edit the code below to shorten the 'Edited Name' to shorten it if it has a space and parentheses so that they will match better. There is another item I can match on which is the SerID but issue is when I add this in the count distinct messes up so I'm trying to figure out if either I can join on data that isn't in the table or join on a name that sort of matches and will if edited in the formula below. 

 

PROC SQL;
 CREATE TABLE WORK.TEST AS
SELECT DISTINCT t1.'Edited Name'n,
t2.'N_DISTINCT_of_SerID'n,
t1.'N_DISTINCT_of_OLH: SupID'n
FROM WORK.TEST t1
FULL JOIN WORK.QUERY_FOR_TEST t2 ON (t1.'Edited Name'n = t2.'OrigName'n)
ORDER BY t1.'N_DISTINCT_of_OLH: SupID'n DESC;
QUIT;

5 REPLIES 5
yabwon
Onyx | Level 15

How about:

on compress(t1.'Edited Name'n,"( )") = compress(t2.'OrigName'n,"( )")

the second argument to compress() function means "delete all spaces and parenthesis". 

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



squeakums
Calcite | Level 5

Where would I add this in the code please?

SASKiwi
PROC Star

You just replace your ON condition in your posted example with @yabwon 's.

ballardw
Super User

Removing parentheses is easy, the Compress function will do that. The question is where is the extra space and would we recognize it as such?

You should provide examples.

 

And if the "count" gets messed up when you have another identification variable then perhaps you don't want to match on only the name as names are unlikely to be unique in any largish real world source, especially if only looking at a first and last name. How do you know that possibly duplicated names are not different people if not looking at other information?

ChrisNZ
Tourmaline | Level 20
You don't specify where the extra space is. Note that trailing spaces are ignored when joining string values.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1037 views
  • 0 likes
  • 5 in conversation