proc compare b=one c=two method =exact listall warning ; /*id USUBJID;*/ run;
Result:
proc compare b=one c=two method =exact listall warning ; id USUBJID; run;
Result:
How can I see both Obs and Usubjid? Is there any statement that allows to do so?
Thank you in advance!
First, this isn't PROC REPORT -- it's PROC COMPARE.
I've skimmed (it could exist) the documentation and didn't see anything. Someone may have a better solution than this, but you could use _N_ in a separate data step before the compare to get this.
Hopefully someone knows a better way.
data my_class;
set sashelp.class;
obs = _n_;
if sex = "M" then sex = "0";
run;
data original_class;
set sashelp.class;
obs = _n_;
run;
proc compare
listbase listcompare
base = original_class
compare = work.my_class;
id obs name;
var sex;
run;
I'm now thinking this may not be a good method. It assumes observation numbers are the same. It got a little problematic when I added an observation in the base data set that didn't exist in the compare data set.
You have seen that the output of PROC COMPARE lists those observations in the report? Here was my example where I added my name to the BASE data set and then compared.
I'm embarrassed how much I've edited this post. You can also output a data set within this procedure. I ran this, and it automatically provides an automatic variable, _OBS_. Here, I used OUTNOEQUAL to output observations where the VAR didn't match.
proc compare
listbase listcompare
base = original_class
compare = work.my_class
outnoequal out = want;
id name;
var sex;
run;
Obs _TYPE_ _OBS_ Name Sex 1 DIF 1 Alfred X 2 DIF 5 Henry X 3 DIF 6 James X 4 DIF 9 Jeffrey X 5 DIF 10 John X 6 DIF 15 Philip X 7 DIF 16 Robert X 8 DIF 17 Ronald X 9 DIF 18 Thomas X 10 DIF 19 William X
Thank you! I corrected topic of my question.
About last Proc Compare you mentined -- it's interesting solution, but it corrupts variables doing them unreadable.
About {obs=_n_} I think it's the most optimal solution of my question.
Comparing datasets by observation and by ID are two different techniques that will give potentially different results. It simply doesn't make sense to combine them as often they will result in two completely different sets of results. I don't see any problem with running two separate COMPAREs each with different results.
If you sort the data set the Obs number will likely change. If you insert new records you may have different values of Obs.
Typically the Obs number is not very helpful for most tasks if you have a unique identifier in the data. Putting it into Proc Report output may imply a permanence of order that is not actually present in many active data sets.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.