<?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: How to count the values of a column based on the value of another in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-count-the-values-of-a-column-based-on-the-value-of/m-p/816190#M34301</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/415512"&gt;@Abelp9&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As far as I see from the preview of your input data, you can use PROC SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select a, /* concat, */ count(distinct concat) as cnt
from have
group by a
/* having cnt&amp;gt;1 */
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You may want to use either or both of the parts that I've commented out to include the CONCAT values in the output dataset or to restrict it to descriptions with at least two different CONCAT values. Note that only &lt;EM&gt;non-missing&lt;/EM&gt; CONCAT values will be counted (without further additions to the code).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Jun 2022 14:02:11 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2022-06-02T14:02:11Z</dc:date>
    <item>
      <title>How to count the values of a column based on the value of another</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-count-the-values-of-a-column-based-on-the-value-of/m-p/816181#M34299</link>
      <description>&lt;P&gt;Hello everyone, I am new to programming in SAS and I have a data sheet like the one in the example, in which column A has descriptions and the last column has the concatenation of all its fields, what I want to see is if that description has concatenations different since it should only have 1 assigned. I had thought about doing a rank by the concatenation field but I don't remember how it was done, could someone give me an example if its possible?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope that if there is an equal description, such as 'GUM', that I put a 1 in the first line and a 2 in the second, so then I can keep those greater than 2, which will be the ones with repeated concatenations, I don't know if I am explaining myself well, I hope so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much in advance, if you help me with this you would do me a great favor&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 12:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-count-the-values-of-a-column-based-on-the-value-of/m-p/816181#M34299</guid>
      <dc:creator>Abelp9</dc:creator>
      <dc:date>2022-06-02T12:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the values of a column based on the value of another</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-count-the-values-of-a-column-based-on-the-value-of/m-p/816182#M34300</link>
      <description>&lt;P&gt;Many of us will not download an Excel spreadsheet (or any MS Office document) as they can be security threats. Please provide (a portion of) your data as &lt;FONT color="#FF0000"&gt;working&lt;/FONT&gt; SAS data step code, which you can type in yourself, or you can follow these &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;instructions&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 12:57:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-count-the-values-of-a-column-based-on-the-value-of/m-p/816182#M34300</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-02T12:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the values of a column based on the value of another</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-count-the-values-of-a-column-based-on-the-value-of/m-p/816190#M34301</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/415512"&gt;@Abelp9&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As far as I see from the preview of your input data, you can use PROC SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select a, /* concat, */ count(distinct concat) as cnt
from have
group by a
/* having cnt&amp;gt;1 */
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You may want to use either or both of the parts that I've commented out to include the CONCAT values in the output dataset or to restrict it to descriptions with at least two different CONCAT values. Note that only &lt;EM&gt;non-missing&lt;/EM&gt; CONCAT values will be counted (without further additions to the code).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 14:02:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-count-the-values-of-a-column-based-on-the-value-of/m-p/816190#M34301</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-06-02T14:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the values of a column based on the value of another</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-count-the-values-of-a-column-based-on-the-value-of/m-p/816205#M34302</link>
      <description>&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a" target="_blank"&gt;https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*create sample data for demonstration;
data have;
    infile cards dlm='09'x;
    input OrgID Product $   States $;
    cards;
1   football    DC
1   football    VA
1   football    MD
2   football    CA
3   football    NV
3   football    CA
;
run;

*Sort - required for both options;
proc sort data=have;
    by orgID;
run;

**********************************************************************;
*Use RETAIN and BY group processing to combine the information;
**********************************************************************;
data want_option1;
    set have;
    by orgID;
    length combined $100.;
    retain combined;

    if first.orgID then
        combined=states;
    else
        combined=catx(', ', combined, states);

    if last.orgID then
        output;
run;

**********************************************************************;
*Transpose it to a wide format and then combine into a single field;
**********************************************************************;
proc transpose data=have out=wide prefix=state_;
    by orgID;
    var states;
run;

data want_option2;
    set wide;
    length combined $100.;
    combined=catx(', ', of state_:);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jun 2022 15:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-count-the-values-of-a-column-based-on-the-value-of/m-p/816205#M34302</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-02T15:12:57Z</dc:date>
    </item>
  </channel>
</rss>

