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
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
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;
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;
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.
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.