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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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