BookmarkSubscribeRSS Feed
Harkonnen
Fluorite | Level 6
proc compare b=one c=two
             method =exact
             listall
             warning
             ;
/*id USUBJID;*/
run;

Result:

Harkonnen_0-1630665166044.png

proc compare b=one c=two
             method =exact
             listall
             warning
             ;
id USUBJID;
run;

Result:

Harkonnen_1-1630665290946.png

How can I see both Obs and Usubjid? Is there any statement that allows to do so?

Thank you in advance!

5 REPLIES 5
maguiremq
SAS Super FREQ

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;

maguiremq_0-1630671510786.png

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.

 

maguiremq_0-1630671844316.png

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

 

Harkonnen
Fluorite | Level 6

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.

SASKiwi
PROC Star

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.

maguiremq
SAS Super FREQ
Can you expand on this? Like how are the variables getting corrupted?
ballardw
Super User

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 638 views
  • 1 like
  • 4 in conversation