<?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: Counting Pairs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-Pairs/m-p/756411#M238804</link>
    <description>&lt;P&gt;You need to create all pairs of values found by each id, followed by a proc freq.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To make the pairs, you can use a data step to:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;make an array of all letters for a givend id.&lt;/LI&gt;
&lt;LI&gt;from that array, construct and output each pair:&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data test;
input ID Letter $;
datalines;
1 A
1 B
2 A
2 B
2 C
3 A
3 B
3 C
3 D
4 A
4 B
4 C
4 D
4 E
run;

data vneed (keep=id pair) / view=vneed;
  array let {8} $8 let1-let8;
  do i=1 by 1 until (last.id);
    set test;
    by id;
    let{i}=letter;
  end;

  do j=1 to i-1;
    do k=j+1 to i;
      pair=cats(let{j},let{k});
      output;
    end;
  end;
run;

proc freq data=vneed;
  tables pair; 
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Make sure to declare the array dimension large enough to accommodate the most populated ID.&lt;/P&gt;</description>
    <pubDate>Sat, 24 Jul 2021 16:35:00 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2021-07-24T16:35:00Z</dc:date>
    <item>
      <title>Counting Pairs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-Pairs/m-p/756407#M238802</link>
      <description>&lt;P&gt;Esteemed Advisers;&lt;/P&gt;
&lt;P&gt;This seems like it should be a simple problem but it is vexing me.&lt;/P&gt;
&lt;P&gt;From the dataset created by the code below, I want to produce Proc Freq table or dataset that produces the following result:&lt;/P&gt;
&lt;P&gt;Pair Count&lt;BR /&gt;AB 4&lt;BR /&gt;AC 3&lt;BR /&gt;AD 2&lt;BR /&gt;AE 1&lt;BR /&gt;BC 3&lt;BR /&gt;BD 2&lt;BR /&gt;BE 1&lt;BR /&gt;CD 2&lt;BR /&gt;CE 1&lt;BR /&gt;DE 1&lt;/P&gt;
&lt;P&gt;I'm looking for suggestions/guidance on how to achieve this result,&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Gene&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data test;
input ID Letter $;
datalines;
1 A
1 B
2 A
2 B
2 C
3 A
3 B
3 C
3 D
4 A
4 B
4 C
4 D
4 E
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 24 Jul 2021 15:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-Pairs/m-p/756407#M238802</guid>
      <dc:creator>genemroz</dc:creator>
      <dc:date>2021-07-24T15:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Pairs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-Pairs/m-p/756411#M238804</link>
      <description>&lt;P&gt;You need to create all pairs of values found by each id, followed by a proc freq.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To make the pairs, you can use a data step to:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;make an array of all letters for a givend id.&lt;/LI&gt;
&lt;LI&gt;from that array, construct and output each pair:&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data test;
input ID Letter $;
datalines;
1 A
1 B
2 A
2 B
2 C
3 A
3 B
3 C
3 D
4 A
4 B
4 C
4 D
4 E
run;

data vneed (keep=id pair) / view=vneed;
  array let {8} $8 let1-let8;
  do i=1 by 1 until (last.id);
    set test;
    by id;
    let{i}=letter;
  end;

  do j=1 to i-1;
    do k=j+1 to i;
      pair=cats(let{j},let{k});
      output;
    end;
  end;
run;

proc freq data=vneed;
  tables pair; 
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Make sure to declare the array dimension large enough to accommodate the most populated ID.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jul 2021 16:35:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-Pairs/m-p/756411#M238804</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-07-24T16:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Pairs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-Pairs/m-p/756416#M238808</link>
      <description>Thanks for your prompt response and excellent solution!&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Gene</description>
      <pubDate>Sat, 24 Jul 2021 17:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-Pairs/m-p/756416#M238808</guid>
      <dc:creator>genemroz</dc:creator>
      <dc:date>2021-07-24T17:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Pairs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-Pairs/m-p/756483#M238849</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data test;
input ID Letter $;
datalines;
1 A
1 B
2 A
2 B
2 C
3 A
3 B
3 C
3 D
4 A
4 B
4 C
4 D
4 E
;

proc sql;
create table want as
select a,b,count(*) as count
 from (select a.letter as a,b.letter as b from test as a,test as b 
        where a.id=b.id and a.letter&amp;lt;b.letter)
  group by a,b;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Jul 2021 11:25:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-Pairs/m-p/756483#M238849</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-07-25T11:25:51Z</dc:date>
    </item>
  </channel>
</rss>

