<?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 Counting number of unique responses by row, across multiple variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-unique-responses-by-row-across-multiple/m-p/768822#M243888</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to count the number of responses across multiple variables. I would like to be able to output a new variable that counts the number of&lt;STRONG&gt; unique&lt;/STRONG&gt; (i.e., the same value in one row should not be counted twice) values across diag_1 to diag_5 &lt;STRONG&gt;excluding&lt;/STRONG&gt; any 'stress' or 'infection' values. Below is the code I have tried thus far based on another solution on this forum, I'm not sure how to finish adapting the code to give me the desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id diag_1 :$9. diag_2 :$9. diag_3 :$9. diag_4 :$9. diag_5 :$9. age;
cards;
01 diabetes stress . . . 42
02 stroke cancer stroke infection death 78
03 stroke copd . copd . 66
;
run;

data want;
set have;
array diag {5} diag_1-diag_5;
array new {5} $9  _temporary_;
do _n_=1 to 5;
   new{_n_} = diag{_n_};
end;
call sortc(of new{*});
count = (new{1} &amp;gt; ' ');
do _n_=2 to 5;
   if new{_n_}  ne new{_n_-1} then count + 1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Output of the above code:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="55.55px" height="15px" class="xl65" style="height: 15.0pt; width: 48pt;"&gt;id&lt;/TD&gt;
&lt;TD width="71.5px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_1&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_2&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_3&lt;/TD&gt;
&lt;TD width="70.6px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_4&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_5&lt;/TD&gt;
&lt;TD width="55.55px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;age&lt;/TD&gt;
&lt;TD width="78.6167px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;treatment&lt;/TD&gt;
&lt;TD width="60.05px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;family&lt;/TD&gt;
&lt;TD width="60.3833px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;Count&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="height: 15.0pt; border-top: none;"&gt;1&lt;/TD&gt;
&lt;TD width="71.5px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;diabetes&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;stress&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="70.6px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;42&lt;/TD&gt;
&lt;TD width="78.6167px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD width="60.05px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;TD width="60.3833px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="height: 15.0pt; border-top: none;"&gt;2&lt;/TD&gt;
&lt;TD width="71.5px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;stroke&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;cancer&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;stroke&lt;/TD&gt;
&lt;TD width="70.6px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;infection&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;death&lt;/TD&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;78&lt;/TD&gt;
&lt;TD width="78.6167px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD width="60.05px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;TD width="60.3833px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="height: 15.0pt; border-top: none;"&gt;3&lt;/TD&gt;
&lt;TD width="71.5px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;stroke&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;copd&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="70.6px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;copd&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;66&lt;/TD&gt;
&lt;TD width="78.6167px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;TD width="60.05px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD width="60.3833px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Desired&lt;/STRONG&gt; output:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 480pt;" border="0" width="640" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="55.55px" height="15px" class="xl65" style="height: 15.0pt; width: 48pt;"&gt;id&lt;/TD&gt;
&lt;TD width="71.5px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_1&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_2&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_3&lt;/TD&gt;
&lt;TD width="70.6px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_4&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_5&lt;/TD&gt;
&lt;TD width="55.55px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;age&lt;/TD&gt;
&lt;TD width="78.6167px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;treatment&lt;/TD&gt;
&lt;TD width="60.05px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;family&lt;/TD&gt;
&lt;TD width="60.3833px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;Count&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="height: 15.0pt; border-top: none;"&gt;1&lt;/TD&gt;
&lt;TD width="71.5px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;diabetes&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;stress&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="70.6px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;42&lt;/TD&gt;
&lt;TD width="78.6167px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD width="60.05px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;TD width="60.3833px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="height: 15.0pt; border-top: none;"&gt;2&lt;/TD&gt;
&lt;TD width="71.5px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;stroke&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;cancer&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;stroke&lt;/TD&gt;
&lt;TD width="70.6px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;infection&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;death&lt;/TD&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;78&lt;/TD&gt;
&lt;TD width="78.6167px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD width="60.05px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;TD width="60.3833px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="height: 15.0pt; border-top: none;"&gt;3&lt;/TD&gt;
&lt;TD width="71.5px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;stroke&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;copd&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="70.6px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;copd&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;66&lt;/TD&gt;
&lt;TD width="78.6167px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;TD width="60.05px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD width="60.3833px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
    <pubDate>Tue, 21 Sep 2021 16:47:18 GMT</pubDate>
    <dc:creator>monsterpie</dc:creator>
    <dc:date>2021-09-21T16:47:18Z</dc:date>
    <item>
      <title>Counting number of unique responses by row, across multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-unique-responses-by-row-across-multiple/m-p/768822#M243888</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to count the number of responses across multiple variables. I would like to be able to output a new variable that counts the number of&lt;STRONG&gt; unique&lt;/STRONG&gt; (i.e., the same value in one row should not be counted twice) values across diag_1 to diag_5 &lt;STRONG&gt;excluding&lt;/STRONG&gt; any 'stress' or 'infection' values. Below is the code I have tried thus far based on another solution on this forum, I'm not sure how to finish adapting the code to give me the desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id diag_1 :$9. diag_2 :$9. diag_3 :$9. diag_4 :$9. diag_5 :$9. age;
cards;
01 diabetes stress . . . 42
02 stroke cancer stroke infection death 78
03 stroke copd . copd . 66
;
run;

data want;
set have;
array diag {5} diag_1-diag_5;
array new {5} $9  _temporary_;
do _n_=1 to 5;
   new{_n_} = diag{_n_};
end;
call sortc(of new{*});
count = (new{1} &amp;gt; ' ');
do _n_=2 to 5;
   if new{_n_}  ne new{_n_-1} then count + 1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Output of the above code:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="55.55px" height="15px" class="xl65" style="height: 15.0pt; width: 48pt;"&gt;id&lt;/TD&gt;
&lt;TD width="71.5px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_1&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_2&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_3&lt;/TD&gt;
&lt;TD width="70.6px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_4&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_5&lt;/TD&gt;
&lt;TD width="55.55px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;age&lt;/TD&gt;
&lt;TD width="78.6167px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;treatment&lt;/TD&gt;
&lt;TD width="60.05px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;family&lt;/TD&gt;
&lt;TD width="60.3833px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;Count&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="height: 15.0pt; border-top: none;"&gt;1&lt;/TD&gt;
&lt;TD width="71.5px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;diabetes&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;stress&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="70.6px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;42&lt;/TD&gt;
&lt;TD width="78.6167px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD width="60.05px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;TD width="60.3833px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="height: 15.0pt; border-top: none;"&gt;2&lt;/TD&gt;
&lt;TD width="71.5px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;stroke&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;cancer&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;stroke&lt;/TD&gt;
&lt;TD width="70.6px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;infection&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;death&lt;/TD&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;78&lt;/TD&gt;
&lt;TD width="78.6167px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD width="60.05px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;TD width="60.3833px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="height: 15.0pt; border-top: none;"&gt;3&lt;/TD&gt;
&lt;TD width="71.5px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;stroke&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;copd&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="70.6px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;copd&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;66&lt;/TD&gt;
&lt;TD width="78.6167px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;TD width="60.05px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD width="60.3833px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Desired&lt;/STRONG&gt; output:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 480pt;" border="0" width="640" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="55.55px" height="15px" class="xl65" style="height: 15.0pt; width: 48pt;"&gt;id&lt;/TD&gt;
&lt;TD width="71.5px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_1&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_2&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_3&lt;/TD&gt;
&lt;TD width="70.6px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_4&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;diag_5&lt;/TD&gt;
&lt;TD width="55.55px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;age&lt;/TD&gt;
&lt;TD width="78.6167px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;treatment&lt;/TD&gt;
&lt;TD width="60.05px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;family&lt;/TD&gt;
&lt;TD width="60.3833px" height="15px" class="xl65" style="border-left: none; width: 48pt;"&gt;Count&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="height: 15.0pt; border-top: none;"&gt;1&lt;/TD&gt;
&lt;TD width="71.5px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;diabetes&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;stress&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="70.6px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;42&lt;/TD&gt;
&lt;TD width="78.6167px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD width="60.05px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;TD width="60.3833px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="height: 15.0pt; border-top: none;"&gt;2&lt;/TD&gt;
&lt;TD width="71.5px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;stroke&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;cancer&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;stroke&lt;/TD&gt;
&lt;TD width="70.6px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;infection&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;death&lt;/TD&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;78&lt;/TD&gt;
&lt;TD width="78.6167px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD width="60.05px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;TD width="60.3833px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="height: 15.0pt; border-top: none;"&gt;3&lt;/TD&gt;
&lt;TD width="71.5px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;stroke&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;copd&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="70.6px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;copd&lt;/TD&gt;
&lt;TD width="62.25px" height="15px" class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="55.55px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;66&lt;/TD&gt;
&lt;TD width="78.6167px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;TD width="60.05px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD width="60.3833px" height="15px" align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 21 Sep 2021 16:47:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-unique-responses-by-row-across-multiple/m-p/768822#M243888</guid>
      <dc:creator>monsterpie</dc:creator>
      <dc:date>2021-09-21T16:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: Counting number of unique responses by row, across multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-unique-responses-by-row-across-multiple/m-p/768886#M243899</link>
      <description>&lt;P&gt;Well, you could check if the value of 'new' does not correspond to one of the terms to exclude before incrementing your count.&lt;/P&gt;
&lt;P&gt;For my part, as counting proceeds rather vertically, i'd like to transpose the 'diags', count them and merge back the results:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id diag_1 :$9. diag_2 :$9. diag_3 :$9. diag_4 :$9. diag_5 :$9. age;
cards;
01 diabetes stress . . . 42
02 stroke cancer stroke infection death 78
03 stroke copd . copd . 66
;
run;

PROC TRANSPOSE data=have out=hlp1;
   by id;
   var diag_1-diag_5;
RUN;

PROC SQL;
   CREATE TABLE hlp2 AS
      SELECT id, count(DISTINCT col1) AS count
      FROM hlp1
      WHERE upcase(col1) NOT IN ('STRESS' 'INFECTION')
      GROUP BY id      
      ;
   CREATE TABLE want AS
      SELECT a.*,b.count
      FROM have a
      LEFT JOIN hlp2 b
      ON a.id eq b.id
    ;
    DROP TABLE hlp1,hlp2
    ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 16:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-unique-responses-by-row-across-multiple/m-p/768886#M243899</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2021-09-21T16:27:36Z</dc:date>
    </item>
  </channel>
</rss>

