<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Comparing all pairs of records / observations in a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparing-all-pairs-of-records-observations-in-a-dataset/m-p/915015#M360579</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/463604"&gt;@Kimani&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also use PROC SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select a.patientid, sum(sign(a.ascore-b.ascore)) as total
from have a, have b
where a.patientid ne b.patientid
group by a.patientid;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I think a more efficient solution would use PROC RANK:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank data=have out=rks(drop=a:);
var ascore;
ranks r;
run;

data want(drop=r);
set rks nobs=n;
total=2*r-n-1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have checked these suggestions with simulated data (not containing missing values, though).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Now I have also completed a mathematical proof of the formula&amp;nbsp;&lt;FONT face="courier new,courier"&gt;total=2*r-n-1&lt;/FONT&gt;.&lt;/P&gt;</description>
    <pubDate>Thu, 08 Feb 2024 12:34:24 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2024-02-08T12:34:24Z</dc:date>
    <item>
      <title>Comparing all pairs of records / observations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-all-pairs-of-records-observations-in-a-dataset/m-p/915001#M360570</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a dataset with say 295 patient observations, I would like to compare all patient pairs on a set of continuous variables, for simplicity let say on one continuous variable, let's call it ASCORE. So the dataset has 2 variables, PATIENTID and ASCORE&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If patient 1 has a larger value for ASCORE than patient 2 then patient 1 earns a value of 1 for that comparison, while patient 2 earns a -1. However if both patients tie, then both earn a 0.&lt;/P&gt;&lt;P&gt;Next I would compare patient 1 to patient 3 and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eventually I would like to calculate the total score for each patient, defined as the sum of points from all their comparisons against the other n-1 patients?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think the solution, lies in using the &lt;STRONG&gt;point option&lt;/STRONG&gt; in a&amp;nbsp;DATA SET step but there could be other ideas.&lt;/P&gt;&lt;P&gt;Any help provided would be great.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2024 04:57:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-all-pairs-of-records-observations-in-a-dataset/m-p/915001#M360570</guid>
      <dc:creator>Kimani</dc:creator>
      <dc:date>2024-02-08T04:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing all pairs of records / observations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-all-pairs-of-records-observations-in-a-dataset/m-p/915015#M360579</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/463604"&gt;@Kimani&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also use PROC SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select a.patientid, sum(sign(a.ascore-b.ascore)) as total
from have a, have b
where a.patientid ne b.patientid
group by a.patientid;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I think a more efficient solution would use PROC RANK:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank data=have out=rks(drop=a:);
var ascore;
ranks r;
run;

data want(drop=r);
set rks nobs=n;
total=2*r-n-1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have checked these suggestions with simulated data (not containing missing values, though).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Now I have also completed a mathematical proof of the formula&amp;nbsp;&lt;FONT face="courier new,courier"&gt;total=2*r-n-1&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2024 12:34:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-all-pairs-of-records-observations-in-a-dataset/m-p/915015#M360579</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-02-08T12:34:24Z</dc:date>
    </item>
  </channel>
</rss>

