BookmarkSubscribeRSS Feed
myrad
Calcite | Level 5
Forgive me if this is easy to do but I am new to SAS.

I am trying to do a proc sql and use a text string as the match key. The only problem is that the string changes between 4 or 2 digits and I need to either do a match to the 4 digit if it exists or to match to the 2 digit if the 4 is not available.

For example in table 1 I have:

ABCD
ABDH
EFGH
GHIJ

In table 2 I have:

AB
ABCD
EF
GHIJ

I would want it to match as:

ABCD -> ABCD
ABDH-> AB
EFGH-> EF
GHIJ-> GHIJ

I hope that makes sense?
2 REPLIES 2
LinusH
Tourmaline | Level 20
Not really. Your "AB" in table 2 will match both "ABCD" and "ABDH" in table 1, unless you specify some other specification to your matching rule. Nevertheless, your join criteria would look something like this:

where table1.id eq table2.id or substr(table1.id,1,2) eq table2.id

/Linus
Data never sleeps
deleted_user
Not applicable
have a look at the (sql-only) comparison operators
EQT
LET
GET
NET
etc.

that trailing"T" implies "truncated to shorter"

PeterC Message was edited by: Peter_c

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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