BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASPhile
Quartz | Level 8

there are two files Master and Target:

Master has id1 and id2 and flag fields.
id1 is a 16 digit number
id2 is a 18 digit number
flag is a 1 digit number


Target has id1 and id2 fields.


Now we need output for the following conditions:
if id1 in both datasets are equal

or

if id2 match (i.e all 18 digits)
or if first tweleve digits and last five digits of id2 in both files match
or if first tweleve digits of id2 match and flag is equal to 1

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You will need to store ID2 as CHARACTER because floating point numbers cannot accurately store 18 digits.

proc sql noprint;

create table want as

select *

from master(rename=(id1=master_id1 id2=master_id2)) m

    , target(rename=(id1=target_id1 id=target_id2)) t

where master_id1 = target_id1

   or master_id2 = target_id2

   or (substr(master_id2,1,12) = substr(target_id2,1,12)

      and (substr(master_id2,14) = substr(target_id2,14)

           or m.flag = 1 )

      )

;

quit;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

You will need to store ID2 as CHARACTER because floating point numbers cannot accurately store 18 digits.

proc sql noprint;

create table want as

select *

from master(rename=(id1=master_id1 id2=master_id2)) m

    , target(rename=(id1=target_id1 id=target_id2)) t

where master_id1 = target_id1

   or master_id2 = target_id2

   or (substr(master_id2,1,12) = substr(target_id2,1,12)

      and (substr(master_id2,14) = substr(target_id2,14)

           or m.flag = 1 )

      )

;

quit;

SASPhile
Quartz | Level 8

Thanks Tom!

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!

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
  • 2 replies
  • 708 views
  • 1 like
  • 2 in conversation