<?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 Number of Distinct Values? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-Distinct-Values/m-p/68098#M19493</link>
    <description>Is there a simple way to determine the number of distinct values in an observation?&lt;BR /&gt;
&lt;BR /&gt;
I'm working with many columns with integer values.  I can use descriptive statistics to determine the number of (non-missing) values or the minimum value etc.&lt;BR /&gt;
&lt;BR /&gt;
numentries = n(of col_start--col_end)&lt;BR /&gt;
minvalue = min(of col_start--col_end)&lt;BR /&gt;
&lt;BR /&gt;
Many values are repeated. I would like to know the number of distinct values there are for each observation.</description>
    <pubDate>Wed, 07 Jan 2009 15:19:05 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-01-07T15:19:05Z</dc:date>
    <item>
      <title>Number of Distinct Values?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-Distinct-Values/m-p/68098#M19493</link>
      <description>Is there a simple way to determine the number of distinct values in an observation?&lt;BR /&gt;
&lt;BR /&gt;
I'm working with many columns with integer values.  I can use descriptive statistics to determine the number of (non-missing) values or the minimum value etc.&lt;BR /&gt;
&lt;BR /&gt;
numentries = n(of col_start--col_end)&lt;BR /&gt;
minvalue = min(of col_start--col_end)&lt;BR /&gt;
&lt;BR /&gt;
Many values are repeated. I would like to know the number of distinct values there are for each observation.</description>
      <pubDate>Wed, 07 Jan 2009 15:19:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Number-of-Distinct-Values/m-p/68098#M19493</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-07T15:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: Number of Distinct Values?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-Distinct-Values/m-p/68099#M19494</link>
      <description>Hi JohnI,&lt;BR /&gt;
&lt;BR /&gt;
I'm not sure what you mean by simple, but something like this might help:&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
input id var1 var2 var3 var4 var5;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 1 2 3 4 5&lt;BR /&gt;
2 1 2 2 3 4&lt;BR /&gt;
3 3 3 2 1 3&lt;BR /&gt;
4 4 1 2 3 1&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want(keep=id var1--var5 n distinct);&lt;BR /&gt;
   set have;&lt;BR /&gt;
   array v_(*) var1--var5;&lt;BR /&gt;
   array _dist_(10) _temporary_;&lt;BR /&gt;
   do j = 1 to 10;&lt;BR /&gt;
      _dist_(j) = .;&lt;BR /&gt;
   end;&lt;BR /&gt;
   do i = 1 to dim(v_);&lt;BR /&gt;
      _dist_(v_(i)) = 1;&lt;BR /&gt;
   end;&lt;BR /&gt;
   distinct = 0;&lt;BR /&gt;
   do j = 1 to 10;&lt;BR /&gt;
      if _dist_(j) ne . then distinct = distinct + 1;&lt;BR /&gt;
   end;&lt;BR /&gt;
   n = n(of var1--var5);  &lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
I've only used five variables and a limit of 10 for the value, but you could extend this for n variables and a wide range of integer values.&lt;BR /&gt;
&lt;BR /&gt;
Robert</description>
      <pubDate>Wed, 07 Jan 2009 16:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Number-of-Distinct-Values/m-p/68099#M19494</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-07T16:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: Number of Distinct Values?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-Distinct-Values/m-p/68100#M19495</link>
      <description>Thank you Robert.&lt;BR /&gt;
&lt;BR /&gt;
By simple I meant a 'one-liner' like N or Max.&lt;BR /&gt;
&lt;BR /&gt;
But, I was able to use your code for my needs (and I learned something too).&lt;BR /&gt;
&lt;BR /&gt;
Thanks again,  John</description>
      <pubDate>Wed, 07 Jan 2009 17:56:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Number-of-Distinct-Values/m-p/68100#M19495</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-07T17:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: Number of Distinct Values?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Number-of-Distinct-Values/m-p/68101#M19496</link>
      <description>Hi:&lt;BR /&gt;
  You could also investigate the NLEVELS option of PROC FREQ or just proc freq in general:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data have;&lt;BR /&gt;
input id var1 var2 var3 var4 var5;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 1 2 3 4 5&lt;BR /&gt;
2 1 2 2 3 4&lt;BR /&gt;
3 3 3 2 1 3&lt;BR /&gt;
4 4 1 2 3 1&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
                                                            &lt;BR /&gt;
proc freq data=have nlevels;&lt;BR /&gt;
  table _numeric_;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 07 Jan 2009 20:38:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Number-of-Distinct-Values/m-p/68101#M19496</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-01-07T20:38:18Z</dc:date>
    </item>
  </channel>
</rss>

