<?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 one column according to a second column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-one-column-according-to-a-second-column/m-p/857281#M338750</link>
    <description>&lt;PRE&gt;proc freq data=have noprint;&lt;BR /&gt;  table a/ nopercent nocum out=cnt(rename=(count=B) drop=percent);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;PROC SQL noprint;&lt;BR /&gt;Create table want as&lt;BR /&gt;  Select * from have join cnt(rename=(a=tmpa)) &lt;BR /&gt;   on have.a = cnt.tmpa;&lt;BR /&gt;Quit;&lt;BR /&gt;&lt;BR /&gt;proc print;&lt;BR /&gt;  var a b;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ghosh_0-1675625897184.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80114i9400CF6F8EF93E4C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ghosh_0-1675625897184.png" alt="ghosh_0-1675625897184.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 05 Feb 2023 19:38:56 GMT</pubDate>
    <dc:creator>ghosh</dc:creator>
    <dc:date>2023-02-05T19:38:56Z</dc:date>
    <item>
      <title>Counting one column according to a second column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-one-column-according-to-a-second-column/m-p/857235#M338713</link>
      <description>&lt;P&gt;Hello everyone and thanks in advance ;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have column A and I need column B&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp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ically count for me how many times the same value has been displayed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Feb 2023 12:16:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-one-column-according-to-a-second-column/m-p/857235#M338713</guid>
      <dc:creator>ziv</dc:creator>
      <dc:date>2023-02-05T12:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: Counting one column according to a second column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-one-column-according-to-a-second-column/m-p/857240#M338718</link>
      <description>&lt;P&gt;It should be done in two steps;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) you can use proc freq to get the frequency of any value in a table&lt;/P&gt;
&lt;P&gt;2) merge the proc freq result table with your original one&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;question - can values repeat like: 1 1 1 2 2 3 3 3 &lt;STRONG&gt;1 1&lt;/STRONG&gt; 4 4.&lt;/P&gt;
&lt;P&gt;would you count &lt;STRONG&gt;3&lt;/STRONG&gt; 2 3 &lt;STRONG&gt;2&lt;/STRONG&gt; 2 or &lt;STRONG&gt;5&lt;/STRONG&gt; 2 3 2&amp;nbsp; ?&lt;/P&gt;</description>
      <pubDate>Sun, 05 Feb 2023 14:26:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-one-column-according-to-a-second-column/m-p/857240#M338718</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2023-02-05T14:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: Counting one column according to a second column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-one-column-according-to-a-second-column/m-p/857257#M338730</link>
      <description>&lt;P&gt;Seems simple enough.&amp;nbsp; Looks like you just want to COUNT.&lt;/P&gt;
&lt;P&gt;First let's convert your listing into an actual dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input A @@ ;
cards;
200 200 200 200 5 5 5 123 123 123 123 123 1 1 1 1 1 1 1
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now we can use BY statement with the NOTSORTED option to figure out where the groups are. We can use one DO loop to count and a second to re-read the actual data and write out all of the observations for the group.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do B=1 by 1 until(last.a);
    set have ;
    by A notsorted ;
  end;
  do until(last.a);
    set have;
    by A notsorted;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;OBS    B      A

  1    4    200
  2    4    200
  3    4    200
  4    4    200
  5    3      5
  6    3      5
  7    3      5
  8    5    123
  9    5    123
 10    5    123
 11    5    123
 12    5    123
 13    7      1
 14    7      1
 15    7      1
 16    7      1
 17    7      1
 18    7      1
 19    7      1
&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Feb 2023 15:57:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-one-column-according-to-a-second-column/m-p/857257#M338730</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-05T15:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: Counting one column according to a second column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-one-column-according-to-a-second-column/m-p/857281#M338750</link>
      <description>&lt;PRE&gt;proc freq data=have noprint;&lt;BR /&gt;  table a/ nopercent nocum out=cnt(rename=(count=B) drop=percent);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;PROC SQL noprint;&lt;BR /&gt;Create table want as&lt;BR /&gt;  Select * from have join cnt(rename=(a=tmpa)) &lt;BR /&gt;   on have.a = cnt.tmpa;&lt;BR /&gt;Quit;&lt;BR /&gt;&lt;BR /&gt;proc print;&lt;BR /&gt;  var a b;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ghosh_0-1675625897184.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80114i9400CF6F8EF93E4C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ghosh_0-1675625897184.png" alt="ghosh_0-1675625897184.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Feb 2023 19:38:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-one-column-according-to-a-second-column/m-p/857281#M338750</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2023-02-05T19:38:56Z</dc:date>
    </item>
    <item>
      <title>Re: Counting one column according to a second column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-one-column-according-to-a-second-column/m-p/858037#M339017</link>
      <description>&lt;P&gt;Hi first of all thank you very much&lt;BR /&gt;Do you know how to do it by chance without BY?&lt;BR /&gt;Because I write it inside an existing command and it doesn't accept BY on my value because it wasn't arranged before in this way.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 14:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-one-column-according-to-a-second-column/m-p/858037#M339017</guid>
      <dc:creator>ziv</dc:creator>
      <dc:date>2023-02-09T14:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: Counting one column according to a second column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-one-column-according-to-a-second-column/m-p/858071#M339023</link>
      <description>&lt;P&gt;If it's easier for you, then there is an option like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have a i need b thank you!!!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 15:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-one-column-according-to-a-second-column/m-p/858071#M339023</guid>
      <dc:creator>ziv</dc:creator>
      <dc:date>2023-02-09T15:54:34Z</dc:date>
    </item>
  </channel>
</rss>

