BookmarkSubscribeRSS Feed
tom16
Calcite | Level 5
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....
8 REPLIES 8
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
tom16
Calcite | Level 5
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....
art297
Opal | Level 21
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_:);
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
tom16
Calcite | Level 5
Thanks for your answers...
it work nice...
Thanks
Peter_C
Rhodochrosite | Level 12
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
Ksharp
Super User
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
Peter_C
Rhodochrosite | Level 12
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
Ksharp
Super User
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 8 replies
  • 1251 views
  • 0 likes
  • 5 in conversation