BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
helmma
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
user24feb
Barite | Level 11

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

4 REPLIES 4
user24feb
Barite | Level 11

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;

anitapamu2
Calcite | Level 5

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;
helmma
Calcite | Level 5

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.

user24feb
Barite | Level 11

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

 

 

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