BookmarkSubscribeRSS Feed
Havi
Obsidian | Level 7


Hi Guys

Please assist. What is the most optimal way to check if two variables exist in 2 separate datasets. The file sizes I am dealing with is quite large - around 50million records in each dataset.

Table 1                    Table 2

A0001                      A0001

A0002                      A0003

A0003                      A0004

A0004                      A0005

A0005

A0006

Output dataset required:

ACCOUNT_ID       STATUS

A0001                     EXISTS in BOTH TABLES

A0002                     DOES NOT EXIST

A0003                     EXISTS in BOTH TABLES

A0004                     EXISTS in BOTH TABLES

A0005                     EXISTS in BOTH TABLES

A0006                     DOES NOT EXIST

Thank you for your assistance.

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, SQL probably isn't the best for this, so try a datastep merge on distinct values:

proc sort data=data1 out=tmp1 nodupkey;

     by account_id;

run;

proc sort data=data2 out=tmp2 nodupkey;

     by account_id;

run;

data want;

     merge tmp1 (in=a) tmp2 (in=b);

     length status $50;

     if a and b then status="In Both";

     else if a then status="Only in A";

     else status="Only in B";

run;

It will take a while to run though just due to the quantity of data.

Ksharp
Super User

Hash Table .

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