Prev: Scatterplot matrix from ODS in PROC CORR
Next: Getting the outcome of a system command into SAS macro variable?
From: maverick2 on 26 Mar 2010 12:45 If I have two datasets, each having one variable and all observations being unique. only that one has more observations than the other. one two var1 var2 ABC ABC AAA AAA CCC CCC ACX XYZ XYZ ZZZ ZZZ Because of this, if I use PROC COMPARE, the output dataset shows first 3 values matching. But even though #5 in one is equal to #4 in two (similarly, #6 in one = #5 in two), the output dataset, from #4 and beyond shows that these are not matching. Is there any way PROC COMPARE can compare the values of a variable irrespective of position? It would be helpful in this case since all observations are unique. Is there anyway using PROC COMPARE I can get matching observations
From: Tom Abernathy on 26 Mar 2010 18:57 That is not really a job for PROC COMPARE as there are no variables other than the ID variable to compare! If you want to match two datasets then just use a MERGE statement. data mismatch ; merge one(in=in1) two(in=in2) ; by id; if not (in1 and in2); if in1 then source='ONE'; if in2 then source='TWO'; run; On Mar 26, 12:45 pm, maverick2 <phekuch...(a)gmail.com> wrote: > If I have two datasets, each having one variable and all observations > being unique. only that one has more observations than the other. > > one two > > var1 var2 > ABC ABC > AAA AAA > CCC CCC > ACX XYZ > XYZ ZZZ > ZZZ > > Because of this, if I use PROC COMPARE, the output dataset shows first > 3 values matching. But even though #5 in one is equal to #4 in two > (similarly, #6 in one = #5 in two), the output dataset, from #4 and > beyond shows that these are not matching. Is there any way PROC > COMPARE can compare the values of a variable irrespective of position? > It would be helpful in this case since all observations are unique. > > Is there anyway using PROC COMPARE I can get matching observations
From: xlr82sas on 26 Mar 2010 18:57
On Mar 26, 9:45 am, maverick2 <phekuch...(a)gmail.com> wrote: > If I have two datasets, each having one variable and all observations > being unique. only that one has more observations than the other. > > one two > > var1 var2 > ABC ABC > AAA AAA > CCC CCC > ACX XYZ > XYZ ZZZ > ZZZ > > Because of this, if I use PROC COMPARE, the output dataset shows first > 3 values matching. But even though #5 in one is equal to #4 in two > (similarly, #6 in one = #5 in two), the output dataset, from #4 and > beyond shows that these are not matching. Is there any way PROC > COMPARE can compare the values of a variable irrespective of position? > It would be helpful in this case since all observations are unique. > > Is there anyway using PROC COMPARE I can get matching observations Hi, I think you want to sort and use an ID variable. Note the non-matching observation is noted, but it does not stop the compare. I will post a Tip on my site with what I consider the best options for proc compare. data base ; input key $; ran=uniform(-1); cards; AAA ABC ACX CCC XYZ ZZZ ; run; data compare; input key $; ran=uniform(-1); cards; AAA ABC CCC XYZ ZZZ ; run; proc compare base=base compare=compare listall; id key; var ran; run; The COMPARE Procedure Comparison of WORK.BASE with WORK.COMPARE (Method=EXACT) Data Set Summary Dataset Created Modified NVar NObs WORK.BASE 26MAR10:15:54:43 26MAR10:15:54:43 2 6 WORK.COMPARE 26MAR10:15:54:43 26MAR10:15:54:43 2 5 Variables Summary Number of Variables in Common: 2. Number of ID Variables: 1. Number of VAR Statement Variables: 1. Comparison Results for Observations Observation 3 in WORK.BASE not found in WORK.COMPARE: KEY=ACX. Observation Summary Number of Variables Compared with Some Observations Unequal: 1. Total Number of Values which Compare Unequal: 5. Maximum Difference: 0.6663.are ID Observation Base Compare ID First Obs 1 1 KEY=AAA First Unequal 1 1 KEY=AAA Last Unequal 6 5 KEY=ZZZ Last Obs 6 5 KEY=ZZZ Number of Observations in Common: 5. Number of Observations in WORK.BASE but not in WORK.COMPARE: 1. Total Number of Observations Read from WORK.BASE: 6. Total Number of Observations Read from WORK.COMPARE: 5. Number of Observations with Some Compared Variables Unequal: 5. Number of Observations with All Compared Variables Equal: 0. he COMPARE Procedure omparison of WORK.BASE with WORK.COMPARE Method=EXACT) ll Variables Compared have Unequal Values ariable Type Len Ndif MaxDif AN NUM 8 5 0.666 alue Comparison Results for Variables _________________________________________________________ || Base Compare KEY || RAN RAN Diff. % Diff ________ || _________ _________ _________ _________ || AAA || 0.007721 0.6740 0.6663 8629 ABC || 0.1086 0.4743 0.3657 336.7910 CCC || 0.5882 0.5458 -0.0424 -7.2061 XYZ || 0.8525 0.4242 -0.4283 -50.2380 ZZZ || 0.4673 0.1327 -0.3346 -71.6029 _________________________________________________________ Hi, I am not sure I know |