Date: Fri, 20 Jun 2008 12:50:02 -0500
Reply-To: Mary <mlhoward@avalon.net>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Mary <mlhoward@AVALON.NET>
Subject: Re: Using PROC COMPARE , comparing by sub group ( patient visit )
Content-Type: text/plain; charset="iso-8859-1"
Ido-
Usually I would try to be more timely in an answer, but I thought you would like an answer nontheless, since another thread has gotten me to think of one! Here you go, note I'm pulling one patient-visit combination and then running the compare stats on it- it puts a summary in the data set called summary (observations within the patient are id1 and id2), and puts the differences in a data set called differences.
Happy Friday!
-Mary
%macro duplicates_compare(vars, varlist);
data allset;
informat id1 4. id2 4. unequal $123.;
if id1=. then delete;
run;
data differences;
informat id1 4. id2 4.;
if id1=. then delete;
run;
data summary;
informat id1 4. id2 4.;
if id1=. then delete;
run;
%Local I;
proc sql noprint;
select count(*) into :model_count
from test;
quit;
%Do I = 1 %To &model_count;
proc sql;
select id into :id1
from test
where obsnum=&i;
quit;
%Do J = &i %To &model_count;
proc sql;
select id into :id2
from test
where obsnum=&j;
quit;
proc sql;
insert into summary
set id1=&id1,
id2=&id2;
quit;
data test1 test2;
set test;
if id=&id1 then output test1;
if id=&id2 then output test2;
run;
data CompareDifferences_set;
informat type $1. batch $123.;
if type='' then delete;
run;
ods trace on;
ods ods output CompareDifferences=CompareDifferences_set comparesummary=comparesummary_set;
proc compare base=test1 compare=test2;
var &varlist;
run;
data CompareDifferences_set2;
informat id1 4. id2 4. batch $123.;
set CompareDifferences_set;
if index(batch,'Obs ||') > 0 or index(batch,'1 ||') > 0;
id1=&id1;
id2=&id2;
keep id1 id2 batch;
run;
data resultset;
informat unequal $123.;
set comparesummary_set;
batch=trim(batch);
if type='d' and index(batch,'Total Number of Values which Compare Unequal')> 0;
id1=&id1;
id2=&id2;
unequal=substr(batch,index(batch,':')+ 1 ,123- index(batch,':')+ 1);
keep id1 id2 unequal;
run;
data allset;
set allset resultset;
run;
data differences;
set differences CompareDifferences_set2;
run;
%End ;
%End ;
data summary;
informat unequal_num 4. equal_num 4. ;
merge summary allset;
by id1 id2;
if unequal='' then unequal='0.';
unequal_num= input(unequal,4.);
equal_num= &vars - unequal_num;
keep id1 id2 unequal_num equal_num;
run;
%Mend duplicates_compare;
data patient_visits;
infile cards;
input patid visit v1 v2 v3;
cards;
101 1 1 3 3
101 1 2 3 3
101 1 1 3 3
101 1 1 3 4
102 1 2 2 4
103 1 2 1 2
103 1 2 1 2
103 1 2 1 2
103 1 2 1 2
103 1 1 1 1
104 2 1 2 1
105 3 2 3 3
106 4 1 2 4
;
run;
data test;
set patient_visits;
where patid=101 and visit=1;
obsnum + 1;
id= obsnum;
run;
title 'Patient ID 101 and Visit 1 Compare';
%duplicates_compare(3, v1--v3);
----- Original Message -----
From: idostatistics@GMAIL.COM
To: SAS-L@LISTSERV.UGA.EDU
Sent: Friday, May 30, 2008 1:33 PM
Subject: Using PROC COMPARE , comparing by sub group ( patient visit )
How do you use PROC COMPARE for , not row-by-row comparison, but
compare by individuals, say by PATIENT or PATIENT-VISIT, to produce an
output dataset that has the rows for all patients or patient-visits
for which the data is in any way different?