BookmarkSubscribeRSS Feed
user112a2
Obsidian | Level 7

I have a question in SAS. How do you normally determine a difference in two data sets? Below is the code that I have used. This is what I have used to determine if records are in one data set but not the other. For example, if someone running the code got higher or lower record counts. I am looking for any alternatives. Thanks.

 

 

Removed
3 REPLIES 3
SuryaKiran
Meteorite | Level 14

If you wanted to compare two datasets then there is a procedure for that PROC COMPARE. 

 

Check this paper for more information http://support.sas.com/resources/papers/proceedings10/149-2010.pdf

 

Thanks,
Suryakiran
ballardw
Super User

SAS has a procedure Proc Compare that may help.  It will report on such things as different types, lengths, formats and labels for variables as well as value comparisons (in possibly more detail than you want sometimes).

It does help if the data sets are sorted.

 

Here is a brief example:

data work.class;
   set sashelp.class;
   if name='John' then sex='F';
   htweight = height*weight;
run;

proc compare base=sashelp.class compare=work.class;
run;

I added a variable so you can see something different in the number of variables and a value so you can see what happens with a different value.

 

You can get different levels of information depending on concerns.

FreelanceReinh
Jade | Level 19

More specifically, in the case of (slightly) different sets of unique keys (combinations of BY variables) in two sorted datasets you would use the ID statement of PROC COMPARE:

proc compare data=lob.req_1_3_17i c=lob.req_1_3_17l listall;
id acct_nb day_time_dim_nb txn_am txn_posting_seq cs_txn_cd req_1_3_excl;
run;

However, I often use a DATA step with a MERGE statement (or a macro containing such code) like you in this case because the output datasets are more suitable for my purposes than those available from PROC COMPARE (not shown in above code; see OUT= option in the documentation).

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 977 views
  • 2 likes
  • 4 in conversation