BookmarkSubscribeRSS Feed
since_92_yahoo_com
Calcite | Level 5

I am sort of a novice SAS user. I was wondering what would be the best way to compare the two tables and only output if there were differences in the data from the two table. I tried using the below code but due to my tables having multiple variables that need to be checked. The sort by one variable is not producing the intended results.

DATA OT_2_current;

  MERGE OT_2_new (IN=T1) OT_2_old (IN=T2);

  BY equip_unit_init_cd;

IF T1 AND NOT T2 THEN OUTPUT OT_2_current;

RUN;

2 REPLIES 2
RichardinOz
Quartz | Level 8

Another option is to use the EXCEPT set operator in Proc SQL.

See Base SAS(R) 9.2 Procedures Guide

Either the columns must be in the same order in both tables or you should user the CORRESPONDING keyword

You can get the unmatched records in table first using something like this (untested)

Proc SQL ;

     Create table firstonly as

          Select * from first

               Except corr

          Select * from second

     ;

Quit ;

Then get the records in the second table not matched in the first by interchanging 'first' and 'second' in the code.

Richard

Message was edited by: Richard Carson

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
  • 345 views
  • 0 likes
  • 3 in conversation