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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 902 views
  • 0 likes
  • 4 in conversation