DATA Step, Macro, Functions and more

Check if two datasets are the same

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Check if two datasets are the same

Hi,

 

I have 2 datasets, how can I compare if they are the same. I am searching for a function that returns true or false


Accepted Solutions
Solution
‎10-15-2015 08:27 AM
Super Contributor
Posts: 336

Re: Check if two datasets are the same

Proc compare has an automatically generated macro-variable which tells you this: &sysinfo. (zero means equal). (use noprint to suppress the output of proc compare).

 

The return codes in detail are here:

 

http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a000146743.htm

 

.. or you could use proc sql or merge or something like this

 

 

View solution in original post


All Replies
Super Contributor
Posts: 336

Re: Check if two datasets are the same

Use Proc Compare:

 

Data A B;
  Do i=1 To 10;
    Output;
  End;
Run;

Data C;
  Do i=2 To 12;
    Output;
  End;
Run;

Proc Compare Base=A Comp=B; Run;
Proc Compare Base=A Comp=C; Run;

Contributor
Posts: 34

Re: Check if two datasets are the same

PROC COMPARE

compares two data sets: the base data set and the comparison data set. The procedure determines matching variables and matching observations. Matching variables are variables with the same name or variables that you pair by using the VAR and WITH statements. Matching variables must be of the same type. Matching observationsare observations that have the same values for all ID variables that you specify or, if you do not use the ID statement, that occur in the same position in the data sets. If you match observations by ID variables, then both data sets must be sorted by all ID variables.

proc compare base=proclib.one
             compare=proclib.two novalues;
run;

 

COMPARE Function

Returns the position of the leftmost character by which two strings differ, or returns 0 if there is no difference.

data test2;
   pad1=compare('abc','abc            ');   
   pad2=compare('abc','abcdef         ');   
   truncate1=compare('abc','abcdef',':');  
   truncate2=compare('abcdef','abc',':');  
   blank=compare('','abc',          ':');   
run;
New Contributor
Posts: 2

Re: Check if two datasets are the same

Maybe I was a bit unclear, I want to compare whole datasets.

 

I have a dataset generated by a script,

it should replace an existing dataset if the contents of those two are different.

 

I need a function or procedure which works like %sysfunc(exist(dataset)) which returns a boolean value (true, false) which can be used in an if-Statement.

Solution
‎10-15-2015 08:27 AM
Super Contributor
Posts: 336

Re: Check if two datasets are the same

Proc compare has an automatically generated macro-variable which tells you this: &sysinfo. (zero means equal). (use noprint to suppress the output of proc compare).

 

The return codes in detail are here:

 

http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a000146743.htm

 

.. or you could use proc sql or merge or something like this

 

 

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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