<?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 Proc sql to count distinct distinct subject or distinct keys in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-to-count-distinct-distinct-subject-or-distinct-keys/m-p/543141#M150131</link>
    <description>&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;
&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; ID1 &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt; ID2 &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;cards&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;
A      O&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;       
B      A &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;     
C      D  &lt;BR /&gt;D      C
&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;E      P &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;       
F      .&lt;BR /&gt;G      F&lt;BR /&gt;H      B&lt;BR /&gt;I      K&lt;BR /&gt;I      L&lt;BR /&gt;I      M
&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;
run;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;I my dataset I have 9 distinct ID1 and and 5 distinct ID2. I want to calculate the total number of distinct id in column ID1 or ID2 . The count should be 14 .&lt;/P&gt;
&lt;P&gt;I am wondering if this can be done in proc sql instead of proc freq? If this can be done in proc sql what would the code be?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;KC&lt;/P&gt;</description>
    <pubDate>Thu, 14 Mar 2019 13:18:58 GMT</pubDate>
    <dc:creator>Kc2</dc:creator>
    <dc:date>2019-03-14T13:18:58Z</dc:date>
    <item>
      <title>Proc sql to count distinct distinct subject or distinct keys</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-to-count-distinct-distinct-subject-or-distinct-keys/m-p/543141#M150131</link>
      <description>&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;
&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; ID1 &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt; ID2 &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;cards&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;
A      O&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;       
B      A &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;     
C      D  &lt;BR /&gt;D      C
&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;E      P &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;       
F      .&lt;BR /&gt;G      F&lt;BR /&gt;H      B&lt;BR /&gt;I      K&lt;BR /&gt;I      L&lt;BR /&gt;I      M
&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class="  language-sas"&gt;
run;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;I my dataset I have 9 distinct ID1 and and 5 distinct ID2. I want to calculate the total number of distinct id in column ID1 or ID2 . The count should be 14 .&lt;/P&gt;
&lt;P&gt;I am wondering if this can be done in proc sql instead of proc freq? If this can be done in proc sql what would the code be?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;KC&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 13:18:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-to-count-distinct-distinct-subject-or-distinct-keys/m-p/543141#M150131</guid>
      <dc:creator>Kc2</dc:creator>
      <dc:date>2019-03-14T13:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql to count distinct distinct subject or distinct keys</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-to-count-distinct-distinct-subject-or-distinct-keys/m-p/543147#M150133</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
SELECT sum(count(DISTINCT ID1), count(DISTINCT ID2)) 
FROM have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Mar 2019 13:32:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-to-count-distinct-distinct-subject-or-distinct-keys/m-p/543147#M150133</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-03-14T13:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql to count distinct distinct subject or distinct keys</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-to-count-distinct-distinct-subject-or-distinct-keys/m-p/543157#M150135</link>
      <description>&lt;P&gt;No this is not correct because ID2 has some ID1 which are in the column ID1. I only want the total of IDs which are unique to ID1 ad ID2, which would be (A,B,C,D,E,F,G,J ,I ,K,L,M,P,O= count=14).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The sum will sum the unique ID1 and Unique ID2&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 13:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-to-count-distinct-distinct-subject-or-distinct-keys/m-p/543157#M150135</guid>
      <dc:creator>Kc2</dc:creator>
      <dc:date>2019-03-14T13:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql to count distinct distinct subject or distinct keys</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-to-count-distinct-distinct-subject-or-distinct-keys/m-p/543162#M150136</link>
      <description>&lt;P&gt;OK, the data step you gave in your question has some formatting problems so your&lt;/P&gt;
&lt;P&gt;goal was unclear.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
SELECT count(DISTINCT ID)
FROM (
    SELECT ID1 AS ID FROM have
	UNION
	SELECT ID2 AS ID FROM have
);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Mar 2019 13:51:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-to-count-distinct-distinct-subject-or-distinct-keys/m-p/543162#M150136</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-03-14T13:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql to count distinct distinct subject or distinct keys</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-to-count-distinct-distinct-subject-or-distinct-keys/m-p/543173#M150139</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/3443"&gt;@Kc2&lt;/a&gt; if the code suggested by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt;&amp;nbsp; does not solve the problem, please re-post the data step, this time using the running-man-icon to preserve formatting.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 14:07:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-to-count-distinct-distinct-subject-or-distinct-keys/m-p/543173#M150139</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-03-14T14:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sql to count distinct distinct subject or distinct keys</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-sql-to-count-distinct-distinct-subject-or-distinct-keys/m-p/543178#M150141</link>
      <description>&lt;P&gt;Thank you it worked&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 14:18:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-sql-to-count-distinct-distinct-subject-or-distinct-keys/m-p/543178#M150141</guid>
      <dc:creator>Kc2</dc:creator>
      <dc:date>2019-03-14T14:18:16Z</dc:date>
    </item>
  </channel>
</rss>

