<?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 sum columns based multiple column values in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-columns-based-multiple-column-values/m-p/559925#M17134</link>
    <description>&lt;P&gt;PROC FREQ allows you to count combinations.&amp;nbsp; If that's what you need, it's fairly straightforward.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
tables yearid * description * gender  / missing list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You might be searching for a slightly different set of counts, but the approach would likely remain the same.&lt;/P&gt;</description>
    <pubDate>Sat, 18 May 2019 22:28:34 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-05-18T22:28:34Z</dc:date>
    <item>
      <title>How to sum columns based multiple column values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-columns-based-multiple-column-values/m-p/559923#M17132</link>
      <description>&lt;P&gt;Hello all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my data, I would like to sum columns based on multiple column criteria. Notmally, for example, if I had a single column to sum like ‘gender’ I would just sum it based on year-id and I could tell how many women I have per year per organization. However, I have 3 columns and I would like to how often each of their unique combinations occurs per year-id. So, I have variables named year-id, description (which is a text based description), and ethnicity (binary variable). There is not a unique id for each observation, something like “1997-101 &amp;nbsp; Tall &amp;nbsp; &amp;nbsp;1’ or ‘1998-102 &amp;nbsp;Short &amp;nbsp; 0’ could appear several times and I want to count how many unique combinations of each observation there are. Also, there are many different description types. If someone could give me some suggestions, I would very much appreciate it!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2019 22:17:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-columns-based-multiple-column-values/m-p/559923#M17132</guid>
      <dc:creator>r4321</dc:creator>
      <dc:date>2019-05-18T22:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum columns based multiple column values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-columns-based-multiple-column-values/m-p/559924#M17133</link>
      <description>&lt;P&gt;Perhaps you could show us a representative portion of your data, &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_self"&gt;following these instructions&lt;/A&gt;, and then also show us the desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, in one place you talk about a sum, but in another place you say "I want to count how many unique combinations of each observation there are". So we need additional clarification there as well.&lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2019 22:40:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-columns-based-multiple-column-values/m-p/559924#M17133</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-18T22:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum columns based multiple column values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-columns-based-multiple-column-values/m-p/559925#M17134</link>
      <description>&lt;P&gt;PROC FREQ allows you to count combinations.&amp;nbsp; If that's what you need, it's fairly straightforward.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
tables yearid * description * gender  / missing list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You might be searching for a slightly different set of counts, but the approach would likely remain the same.&lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2019 22:28:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-columns-based-multiple-column-values/m-p/559925#M17134</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-05-18T22:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum columns based multiple column values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-columns-based-multiple-column-values/m-p/559929#M17135</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83117"&gt;@r4321&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't fully understand what you're asking for so below just as a thought options how you could generate an additional variable Group ID - just to make further coding simpler.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input (yearid description gender) ($) ethnicity otherVar $;
  datalines;
1 aaa F 0 W
1 bbb M 1 X
1 aaa F 0 Y
2 aaa F 0 Z
;
run;

/* option 1 */
data option1;
  set have;
  groupID=put(md5(upcase(catx('|',yearid,description,gender,ethnicity))),hex32.);
run;

/* option 2 */
proc sort data=have out=option2;
  by yearid description gender ethnicity;
run;
data option2;
  set option2;
  by yearid description gender ethnicity;
  if first.ethnicity then groupID+1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;MD5() used in option 1 is deterministic and will for the same source string always return the same hash value (digest value). This can be useful to combine data from different sources.&lt;/P&gt;
&lt;P&gt;I've added the upcase() funtion to make the hash value generation case insensitive.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 May 2019 02:15:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-columns-based-multiple-column-values/m-p/559929#M17135</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-05-19T02:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum columns based multiple column values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-columns-based-multiple-column-values/m-p/559962#M17138</link>
      <description>Thank you!</description>
      <pubDate>Sun, 19 May 2019 17:30:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-sum-columns-based-multiple-column-values/m-p/559962#M17138</guid>
      <dc:creator>r4321</dc:creator>
      <dc:date>2019-05-19T17:30:53Z</dc:date>
    </item>
  </channel>
</rss>

