<?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: Proc SQL Distinct Gives different Results in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-Distinct-Gives-different-Results/m-p/978696#M43574</link>
    <description>&lt;P&gt;No.&amp;nbsp; Because the PROC SORT could have eliminated some observations with IND=1.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp1;
  input var_id ind ;
cards;
1 1
1 2
1 3
2 2
2 1
3 2
;

proc sort data=temp1 out=temp2 nodupkey;
  by var_id;
run;

proc sql;
  select 'TEMP1' as source, count(distinct case when (ind=1) then var_id end) as count from temp1
  union
  select 'TEMP2' as source, count(distinct case when (ind=1) then var_id end) as count from temp2
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1762881658200.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/111241i18E9E09393E6EB4E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1762881658200.png" alt="Tom_0-1762881658200.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Nov 2025 20:10:10 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-11-11T20:10:10Z</dc:date>
    <item>
      <title>Proc SQL Distinct Gives different Results</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-Distinct-Gives-different-Results/m-p/978693#M43573</link>
      <description>&lt;P&gt;I have a data set where I want to count number of distinct var_id when ind=1. I use proc sql with distinct option for that. See code below. However when I first remove the duplicates on var_id and then use&amp;nbsp;proc sql with distinct option I get a different answer. Shouldn't they give the same answer since the distinct option takes care of this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=temp1 out=temp2 nodupkey;&lt;/P&gt;
&lt;P&gt;by var_id;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;select count(distinct case when (ind=1) then var_id end)&lt;/P&gt;
&lt;P&gt;from temp1;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;select count(distinct case when (ind=1) then var_id end)&lt;/P&gt;
&lt;P&gt;from temp2;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Nov 2025 16:46:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-Distinct-Gives-different-Results/m-p/978693#M43573</guid>
      <dc:creator>trevand</dc:creator>
      <dc:date>2025-11-11T16:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Distinct Gives different Results</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-Distinct-Gives-different-Results/m-p/978696#M43574</link>
      <description>&lt;P&gt;No.&amp;nbsp; Because the PROC SORT could have eliminated some observations with IND=1.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp1;
  input var_id ind ;
cards;
1 1
1 2
1 3
2 2
2 1
3 2
;

proc sort data=temp1 out=temp2 nodupkey;
  by var_id;
run;

proc sql;
  select 'TEMP1' as source, count(distinct case when (ind=1) then var_id end) as count from temp1
  union
  select 'TEMP2' as source, count(distinct case when (ind=1) then var_id end) as count from temp2
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1762881658200.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/111241i18E9E09393E6EB4E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1762881658200.png" alt="Tom_0-1762881658200.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Nov 2025 20:10:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-SQL-Distinct-Gives-different-Results/m-p/978696#M43574</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-11-11T20:10:10Z</dc:date>
    </item>
  </channel>
</rss>

