<?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: get the value that appear in largest number of groups in the dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/get-the-value-that-appear-in-largest-number-of-groups-in-the/m-p/726474#M225725</link>
    <description>&lt;P&gt;Can you have duplicate entries of the Y per X? What if there are ties in the most frequent?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this could get you started&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql outobs=1;
create table want as
select y, count(distinct x) as num_groups
from have
group by y
order by 2 desc, 1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You're essentially looking to do distinct counts per item, rather than per group so reframing the question makes it fairly trivial.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/count_distinct_by_group.sas" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/count_distinct_by_group.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/373967"&gt;@Mohammed_123&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;I started learning SAS one week ago. I know some basics like data steps, loops, BY statement and how it creates First and Last variables, some Procedures like Sort.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset divided into groups, each group has different number of observations:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;example of how that dataset would look like:&amp;nbsp;&lt;BR /&gt;x y&amp;nbsp;&lt;BR /&gt;a 0&lt;BR /&gt;a 5&lt;BR /&gt;a 22&lt;BR /&gt;b 22&lt;BR /&gt;b 3&amp;nbsp;&lt;BR /&gt;c 5&lt;BR /&gt;c 22&lt;BR /&gt;c 14&lt;BR /&gt;c 9&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;So in this case, 22 appears in 3 groups so the result will be 22.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I just want to know the idea of how to implement that, I thought of comparing each observation for all other observations and so on, but this makes no sense in case if I have a big dataset.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 15 Mar 2021 17:36:19 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-03-15T17:36:19Z</dc:date>
    <item>
      <title>get the value that appear in largest number of groups in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-value-that-appear-in-largest-number-of-groups-in-the/m-p/726413#M225703</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;I started learning SAS one week ago. I know some basics like data steps, loops, BY statement and how it creates First and Last variables, some Procedures like Sort.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset divided into groups, each group has different number of observations:&amp;nbsp;&lt;/P&gt;&lt;P&gt;example of how that dataset would look like:&amp;nbsp;&lt;BR /&gt;x y&amp;nbsp;&lt;BR /&gt;a 0&lt;BR /&gt;a 5&lt;BR /&gt;a 22&lt;BR /&gt;b 22&lt;BR /&gt;b 3&amp;nbsp;&lt;BR /&gt;c 5&lt;BR /&gt;c 22&lt;BR /&gt;c 14&lt;BR /&gt;c 9&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;So in this case, 22 appears in 3 groups so the result will be 22.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I just want to know the idea of how to implement that, I thought of comparing each observation for all other observations and so on, but this makes no sense in case if I have a big dataset.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 14:53:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-value-that-appear-in-largest-number-of-groups-in-the/m-p/726413#M225703</guid>
      <dc:creator>Mohammed_123</dc:creator>
      <dc:date>2021-03-15T14:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: get the value that appear in largest number of groups in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-value-that-appear-in-largest-number-of-groups-in-the/m-p/726465#M225722</link>
      <description>&lt;P&gt;I think we need a little more information. Are you just looking to get the mode? Or are you trying to only keep records that have that max value? Here's one way to show the most frequent value, but I don't know if it's what you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x $ y;
datalines;
a 0
a 5
a 22
b 22
b 3 
c 5
c 22
c 14
c 9
;
run;

proc freq data = have order = freq noprint;
	tables y / out = want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 17:11:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-value-that-appear-in-largest-number-of-groups-in-the/m-p/726465#M225722</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-03-15T17:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: get the value that appear in largest number of groups in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-value-that-appear-in-largest-number-of-groups-in-the/m-p/726474#M225725</link>
      <description>&lt;P&gt;Can you have duplicate entries of the Y per X? What if there are ties in the most frequent?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this could get you started&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql outobs=1;
create table want as
select y, count(distinct x) as num_groups
from have
group by y
order by 2 desc, 1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You're essentially looking to do distinct counts per item, rather than per group so reframing the question makes it fairly trivial.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/count_distinct_by_group.sas" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/count_distinct_by_group.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/373967"&gt;@Mohammed_123&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;I started learning SAS one week ago. I know some basics like data steps, loops, BY statement and how it creates First and Last variables, some Procedures like Sort.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset divided into groups, each group has different number of observations:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;example of how that dataset would look like:&amp;nbsp;&lt;BR /&gt;x y&amp;nbsp;&lt;BR /&gt;a 0&lt;BR /&gt;a 5&lt;BR /&gt;a 22&lt;BR /&gt;b 22&lt;BR /&gt;b 3&amp;nbsp;&lt;BR /&gt;c 5&lt;BR /&gt;c 22&lt;BR /&gt;c 14&lt;BR /&gt;c 9&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;So in this case, 22 appears in 3 groups so the result will be 22.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I just want to know the idea of how to implement that, I thought of comparing each observation for all other observations and so on, but this makes no sense in case if I have a big dataset.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 17:36:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-value-that-appear-in-largest-number-of-groups-in-the/m-p/726474#M225725</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-15T17:36:19Z</dc:date>
    </item>
  </channel>
</rss>

