<?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 total number of distinct observation in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/counting-total-number-of-distinct-observation/m-p/430835#M68642</link>
    <description>Thanks Shmuel</description>
    <pubDate>Thu, 25 Jan 2018 09:45:33 GMT</pubDate>
    <dc:creator>babymonster</dc:creator>
    <dc:date>2018-01-25T09:45:33Z</dc:date>
    <item>
      <title>counting total number of distinct observation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counting-total-number-of-distinct-observation/m-p/430818#M68639</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I have a data set that contain a variable similar to this example,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;number&lt;/P&gt;&lt;P&gt;56&lt;/P&gt;&lt;P&gt;56&lt;/P&gt;&lt;P&gt;56&lt;/P&gt;&lt;P&gt;58&lt;/P&gt;&lt;P&gt;58&lt;/P&gt;&lt;P&gt;60&lt;/P&gt;&lt;P&gt;61&lt;/P&gt;&lt;P&gt;61&lt;/P&gt;&lt;P&gt;61&lt;/P&gt;&lt;P&gt;61&lt;/P&gt;&lt;P&gt;61&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to know the total count of distinct number. In this example is 4 (56, 58, 60, and 61).&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can i do it in SAS? I think i can do&lt;/P&gt;&lt;P&gt;proc sort data= mydata out=dataout noduplications;&lt;/P&gt;&lt;P&gt;...&amp;nbsp;&lt;/P&gt;&lt;P&gt;then use proc freq or proc means&lt;/P&gt;&lt;P&gt;but is that a clever way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 08:58:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counting-total-number-of-distinct-observation/m-p/430818#M68639</guid>
      <dc:creator>babymonster</dc:creator>
      <dc:date>2018-01-25T08:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: counting total number of distinct observation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counting-total-number-of-distinct-observation/m-p/430822#M68640</link>
      <description>&lt;P&gt;There are more than one way to get the amount of distinct values of a variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Using proc sort with nodupkey - just check number of output observations in log or check output dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Use proc sql - select distinct variable and end with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;quit;
%put &amp;amp;sqlobs;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; then check the log;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) Assuming your data is sorted by the variable then do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   set have end=eof;
        retain distinct_count 0;
    by var;
        if eof then put   distinct_count =;
        if first.var then  distinct_count  +1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; and check the log;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 09:50:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counting-total-number-of-distinct-observation/m-p/430822#M68640</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-01-25T09:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: counting total number of distinct observation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counting-total-number-of-distinct-observation/m-p/430835#M68642</link>
      <description>Thanks Shmuel</description>
      <pubDate>Thu, 25 Jan 2018 09:45:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counting-total-number-of-distinct-observation/m-p/430835#M68642</guid>
      <dc:creator>babymonster</dc:creator>
      <dc:date>2018-01-25T09:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: counting total number of distinct observation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counting-total-number-of-distinct-observation/m-p/430845#M68643</link>
      <description>&lt;P&gt;You want to do a frequency count, therefore use proc freq(uency) - this is logical and why they called the procedure that name&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 10:29:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counting-total-number-of-distinct-observation/m-p/430845#M68643</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-25T10:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: counting total number of distinct observation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/counting-total-number-of-distinct-observation/m-p/430985#M68646</link>
      <description>&lt;P&gt;And an example using the Proc Freq nlevels option:&lt;/P&gt;
&lt;PRE&gt;ods select nlevels;
proc freq data=sashelp.class nlevels;
   tables sex;
run;&lt;/PRE&gt;
&lt;P&gt;the ODS Select nlevels; instructs SAS to only show the levels information which would be the number of unique values and missing values if any.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 16:35:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/counting-total-number-of-distinct-observation/m-p/430985#M68646</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-25T16:35:57Z</dc:date>
    </item>
  </channel>
</rss>

