Help using Base SAS procedures

Proc Compare to get output data set

Reply
Occasional Contributor
Posts: 13

Proc Compare to get output data set

data A
id name age score1 score2 score3 score4
111 tom 30 230 240 260 .
222 robert 42 258 239 360 .
333 rob 28 308 246 218 .
444 gary 35 234 289 290 .

data B
id name age score1 score2 score3 score4
111 tom 30 230 240 260
222 robert 40 258 225 356
333 rob 28 301 246 218
444 gary 34 234 289 256

I want to use proc compare and want output like this:
-> compare data A with data B and in output data set C
want missing value when values are same in both data sets
and wants values from data set A when values are different in
data A and data B.

Please give syntex and output if you can...

Thanks in advance for your help....
Super Contributor
Super Contributor
Posts: 3,174

Re: Proc Compare to get output data set

Recommend starting with the available DOC and other technical papers available at SAS support http://support.sas.com/ website.

PROC COMPARE has a NOPRINT feature, as documented, along with an output dataset. You can generate the output, analyze it for content, and create a suitable report with either PROC PRINT, a DATA step directly, or PROC REPORT.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

proc compare output dataset analysis site:sas.com
Occasional Contributor
Posts: 13

Re: Proc Compare to get output data set

Hi Scoot,

Thanks for your help..with your help I get this one:

data A;
input id name $ age score1 score2 score3;
cards;

222 robert 42 258 239 360
333 rob 28 308 246 218
444 gary 35 234 289 290
;
run;
data B;
input id name $ age score1 score2 score3 ;
cards;

222 robert 40 258 225 356 222
333 rob 28 301 246 218
444 gary 34 234 289 256
;
run;

proc compare data=A
compare=B
outnoequal
out=C
noprint
outcomp
outbase;
id
;
run;

OUTOUT:

_TYPE_ _OBS_ id name age score1 score2 score3
BASE 2 222 robert 42 258 239 360
COMPARE 2 222 robert 40 258 225 356
BASE 3 333 rob 28 308 246 218
COMPARE 3 333 rob 28 301 246 218
BASE 4 444 gary 35 234 289 290
COMPARE 4 444 gary 34 234 289 256

But still I want to compare data set A with data set B and if both values are same then I want missing/blank on that place of observation and if it's different then I want value of data set A by ID...will appreciate if any help...

Thanks....
PROC Star
Posts: 7,363

Re: Proc Compare to get output data set

Tom,

Since you want something other than what proc compare provides, why don't you just roll your own compare with a datastep? E.g., I think that the following comes close to your specs:


data want (drop=i b_Smiley Happy;
merge a b (rename=(age=b_age score1-score3=b_score1-b_score3));
by id name;
array a_data(*) age score1-score3;
array b_data(*) b_age b_score1-b_score3;
do i=1 to dim(a_data);
if a_data(i) eq b_data(i) then call missing(a_data(i));
end;
run;

HTH,
Art
Occasional Contributor
Posts: 13

Re: Proc Compare to get output data set

Thanks for your answers...
it work nice...
Thanks
Valued Guide
Posts: 2,175

Re: Proc Compare to get output data set

When you remove the demand for PROC COMPARE (or whatever) solutions, simpler alternatives might be offered.
As Art has recommended DATA STEP I will draw attention to PROC SQL and it's set operator EXCEPT. It makes this request seem almost trivial
PROC SQL ;
Create table differences as select * from A except select * from B;
Quit;

Of course this is a row rather than individual column compare, but still worth considering.
IMHO

peterC
Super User
Posts: 9,682

Re: Proc Compare to get output data set

Hi.Peter.
Maybe you misunderstood op's mean.op want missing when both are same.
your sql code is only except the obs in B from A and they both have the same variables.

Regards

Ksharp
Valued Guide
Posts: 2,175

Re: Proc Compare to get output data set

kSharp
Thank you
that might paraphrase my last sentence.
I was surprised and did not expect to provide a row on output which held only missing values.
So did not think the original posted question entirely clear. However, I thought that SQL form of compare would be worth reviewing. Don't you agree?

peterC
Super User
Posts: 9,682

Re: Proc Compare to get output data set

Agree!.
Each of Data-step and Proc-sql has its virtues respectively,then If have skill of both ,you
will be a perfect SAS programmer.


Ksharp
Ask a Question
Discussion stats
  • 8 replies
  • 141 views
  • 0 likes
  • 5 in conversation