<?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: Sum values by classes and format the output in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888343#M39437</link>
    <description>&lt;P&gt;Here's the problem. In order to write code, you have to know the inputs, which you have provided; and you have to know the outputs from those inputs (which you have not provided because your outputs have values for CAT = 5 and so this does not correspond to the inputs), and you have to know the logic to get from inputs to outputs. So I'm stuck, and I'm afraid I still don't understand what the method is and I still don't understand the method to get from inputs to outputs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And even if you explain the CAT5 issue, its still not clear to me how to get the other categories either. Please explain in words&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;the whole thing&lt;/FONT&gt;&lt;/STRONG&gt;. Step by step examples are good. Do not make me guess what to do. Do not make me guess what the steps are.&lt;/P&gt;</description>
    <pubDate>Tue, 08 Aug 2023 12:50:43 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-08-08T12:50:43Z</dc:date>
    <item>
      <title>Sum values by classes and format the output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888313#M39425</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data DB1;&lt;BR /&gt;input cat1 cat2 cat3 cat4 cat5 place value;&lt;BR /&gt;cards;&lt;BR /&gt;0 0 0 0 0 1 125&lt;BR /&gt;0 0 0 0 0 2 33&lt;BR /&gt;0 0 0 0 0 3 44&lt;BR /&gt;0 0 1 0 0 1 2&lt;BR /&gt;0 0 1 0 0 2 .&lt;BR /&gt;0 0 1 0 0 3 1&lt;BR /&gt;0 1 0 0 0 1 .&lt;BR /&gt;0 1 0 0 0 2 .&lt;BR /&gt;0 1 0 0 0 3 .&lt;BR /&gt;0 1 0 1 0 1 65&lt;BR /&gt;0 1 0 1 0 2 36&lt;BR /&gt;0 1 0 1 0 3 43&lt;BR /&gt;0 1 1 0 0 1 .&lt;BR /&gt;0 1 1 0 0 2 .&lt;BR /&gt;0 1 1 1 0 1 4&lt;BR /&gt;0 1 1 1 0 2 2&lt;BR /&gt;1 0 0 0 0 1 164&lt;BR /&gt;1 0 0 0 0 2 516&lt;BR /&gt;1 0 0 0 0 3 619&lt;BR /&gt;1 0 1 0 0 1 5&lt;BR /&gt;1 0 1 0 0 2 1&lt;BR /&gt;1 0 1 0 0 3 2&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to generate this desired output?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data DB2;&lt;BR /&gt;input CAT Place Value ;&lt;BR /&gt;cards;&lt;BR /&gt;0 1 125&lt;/P&gt;
&lt;P&gt;0 2 33&lt;/P&gt;
&lt;P&gt;0 3 44&lt;/P&gt;
&lt;P&gt;1 1 169&lt;/P&gt;
&lt;P&gt;1 2 517&lt;/P&gt;
&lt;P&gt;1 3 621&lt;/P&gt;
&lt;P&gt;2 1 69&lt;/P&gt;
&lt;P&gt;2 2 38&lt;/P&gt;
&lt;P&gt;2 3 43&lt;/P&gt;
&lt;P&gt;3 1 7&lt;/P&gt;
&lt;P&gt;3 2 1&lt;/P&gt;
&lt;P&gt;3 3 3&lt;/P&gt;
&lt;P&gt;4 1 69&lt;/P&gt;
&lt;P&gt;4 2 38&lt;/P&gt;
&lt;P&gt;4 3 43&lt;/P&gt;
&lt;P&gt;5 1 0&lt;/P&gt;
&lt;P&gt;5 2 0&lt;/P&gt;
&lt;P&gt;5 3 0&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In other words, I would like to sum all values in column value for each cat* by place 1,2,3. It doesn't matter if cat* are not mutually exclusive. Moreover, the output should be presented as a single column of cat stratified by "place". Can you help me please?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;looking at the cat5: it has all "0s". As a rule, if all the other cat*(s) in DB1 have 0 (i.e., no "1" index), in DB2 "CAT" will be number "0". This means that cat5 specific values will be 0 because no "1" index is found for that cat* in DB1. Conversely it will be in CAT "0" for values 125, 33 and 44 because all the other cat* are 0 (no "1" index in DB1). Based on this, in DB2 we will see CAT 5 = 0 for place 1,2 and 3 because no specific values are found for cat5 (corresponding to "1" in DB1). For all the other cases, simply a sum of "value" is required for each "CAT*" in DB1 by "place".&lt;/P&gt;
&lt;P&gt;Example: let's consider cat1 column in DB1 that will become CAT = 1 in DB2. If we look at all times we see "1"index, for place 1 we will have values in DB1 equal to: 164 and 5. I just need to sum them to get 169. For place 2 we have: 516 and 1 that after the sum will become 517 and for place 3 we have 619 and 2 that after the sum will become 621. This is the output I need.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: the sum must be performed REGARDLESS what happens in the other "cat*" in DB1 except for 0 as explained above.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 13:27:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888313#M39425</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2023-08-08T13:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values by classes and format the output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888321#M39426</link>
      <description>&lt;P&gt;I don't understand the relationship of CAT in DB2 (which has values 1 to 5) to the data in DB1. Please explain further how CAT=1 in DB2 is derived from DB1.&amp;nbsp;Please explain further how CAT=2 in DB2 is derived from DB1. And so on.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 12:08:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888321#M39426</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-08T12:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values by classes and format the output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888324#M39427</link>
      <description>&lt;P&gt;So, basically there are 5 cat* that in DB1 are on columns while in DB2 will be in one column with indexes from 1 to 5 based on the column name cat1, cat2, cat3, cat4, cat5 in DB1&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 12:18:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888324#M39427</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2023-08-08T12:18:11Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values by classes and format the output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888330#M39430</link>
      <description>&lt;P&gt;I'm afraid this really doesn't explain the issue. The values for CAT5 are all zeros. How is there a CAT = 5 in the output?&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 12:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888330#M39430</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-08T12:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values by classes and format the output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888338#M39434</link>
      <description>&lt;P&gt;So: there are no patients in category 5 for all the three places (1,2,3) with a value in value column (otherwise you should see "1" in the column cat5)regardless any value in cat*(1-4). Despite this, cat5 must appear in DB2 to say "we cannot find patients in cat5 with a value different from 0 for all the three places". In DB1 categories are listed in columns as: cat*(1-5) while in DB2 from 1 to 5&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 12:35:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888338#M39434</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2023-08-08T12:35:43Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values by classes and format the output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888343#M39437</link>
      <description>&lt;P&gt;Here's the problem. In order to write code, you have to know the inputs, which you have provided; and you have to know the outputs from those inputs (which you have not provided because your outputs have values for CAT = 5 and so this does not correspond to the inputs), and you have to know the logic to get from inputs to outputs. So I'm stuck, and I'm afraid I still don't understand what the method is and I still don't understand the method to get from inputs to outputs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And even if you explain the CAT5 issue, its still not clear to me how to get the other categories either. Please explain in words&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;the whole thing&lt;/FONT&gt;&lt;/STRONG&gt;. Step by step examples are good. Do not make me guess what to do. Do not make me guess what the steps are.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 12:50:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888343#M39437</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-08T12:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values by classes and format the output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888345#M39438</link>
      <description>Ok, I understand the point. I will edit the post</description>
      <pubDate>Tue, 08 Aug 2023 12:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888345#M39438</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2023-08-08T12:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values by classes and format the output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888350#M39440</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134532"&gt;@NewUsrStat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Ok, I understand the point. I will edit the post&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please do &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;not&lt;/FONT&gt; &lt;/STRONG&gt;modify the original post. Please explain in a reply. Otherwise, if you modify the original post, then the thread makes no sense to anyone.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or start a brand new thread.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 13:03:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888350#M39440</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-08T13:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values by classes and format the output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888351#M39441</link>
      <description>I just added an explanation. Hope it is more clear</description>
      <pubDate>Tue, 08 Aug 2023 13:09:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888351#M39441</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2023-08-08T13:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values by classes and format the output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888355#M39442</link>
      <description>&lt;P&gt;Okay, I think I understand now. Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a brute force solution, but it seems to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro do_this;
    proc delete data=db2; run; quit;
    %do i=1 %to 5;
        proc summary data=db1 nway;
            class place;
            var value;
            weight cat&amp;amp;i;
            output out=out sum=;
        run;
        data out;
            set out;
            cat=&amp;amp;i;
        run;
        proc append base=db2 new=out;
        run;
        proc delete data=out; run; quit;
    %end;
%mend;
%do_this
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Aug 2023 13:32:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888355#M39442</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-08T13:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values by classes and format the output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888356#M39443</link>
      <description>&lt;P&gt;Sounds like CAT1 to CAT5 are BOOLEAN flags.&amp;nbsp; Perhaps meaning that Category 1 (or 2 or ...) was present.&lt;/P&gt;
&lt;P&gt;Sounds like the goal is to find the maximum category that has present?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  set want;
  array cats cat1-cat5;
  cat=0;
  do index=1 to dim(cats);
     if cats[index] then cat=index;
  end;
  drop index;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Aug 2023 13:34:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888356#M39443</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-08T13:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values by classes and format the output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888361#M39444</link>
      <description>Really thank you very much!!!!! It works perfectly!</description>
      <pubDate>Tue, 08 Aug 2023 13:53:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888361#M39444</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2023-08-08T13:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values by classes and format the output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888363#M39445</link>
      <description>Not exactly Tom. Just to sum values by place (1-3) for each category with the exception of all "0" in all categories in DB1 as I explained in the post</description>
      <pubDate>Tue, 08 Aug 2023 13:54:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888363#M39445</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2023-08-08T13:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values by classes and format the output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888364#M39446</link>
      <description>Sorry but why "0" disappears in the output. I need</description>
      <pubDate>Tue, 08 Aug 2023 13:57:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888364#M39446</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2023-08-08T13:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values by classes and format the output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888365#M39447</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134532"&gt;@NewUsrStat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Not exactly Tom. Just to sum values by place (1-3) for each category with the exception of all "0" in all categories in DB1 as I explained in the post&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To SUM a set of variable in a single observation just use the SUM() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have;
  cat = sum(of cat1-cat5);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To SUM a series of variables just use PROC SUMMARY (aka PROC MEANS).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;
   output out=want sum(cat1-cat5)= ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want separate sums for each value of PLACE then you could add PLACE as a CLASS variable.&lt;/P&gt;
&lt;P&gt;But you will still have five variables named CAT1 to CAT5 that now have the sums.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not see how that would get you a single variable named CAT.&amp;nbsp; Unless you wanted to TRANSPOSE the data so that you have 5 observations.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary nway data=have;
  class place;
  var cat1-cat5 ;
  output out=wide sum= ;
run;

proc transpose data=wide out=tall;
  by place;
  var cat1-cat5 ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1691503877396.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/86526i66F2B2CC329FFCA7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1691503877396.png" alt="Tom_0-1691503877396.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you have not explained what role that last variable VALUE has in this at all.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 14:11:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888365#M39447</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-08T14:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values by classes and format the output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888386#M39449</link>
      <description>Thank you Tom, but still "0" remains out. I also need to count (or sum) when all cat* have "0" to get 125, 33, 44. This output seems to disappear but I need to show numbers when no one has "1" in DB1</description>
      <pubDate>Tue, 08 Aug 2023 14:41:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888386#M39449</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2023-08-08T14:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values by classes and format the output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888434#M39454</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134532"&gt;@NewUsrStat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you Tom, but still "0" remains out. I also need to count (or sum) when all cat* have "0" to get 125, 33, 44. This output seems to disappear but I need to show numbers when no one has "1" in DB1&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have no idea what that means.&lt;/P&gt;
&lt;P&gt;Please create a small precise example of input and the results you want.&amp;nbsp; Explain in detail how you get that results from that input.&amp;nbsp; Spell out the STORY.&amp;nbsp; What do the CAT1 to CAT5 variables represent? What do the other two variables represent?&amp;nbsp; What to the observations in the input represent?&amp;nbsp; What do the observations in the output represent? What do the variables in the output represent?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you asking to create variables other than the 5 that exist in the data?&amp;nbsp; How do you know how many variables there could be?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 18:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888434#M39454</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-08T18:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values by classes and format the output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888448#M39455</link>
      <description>So, regarding CAT =0 I mean just to add the frequencies when all cat*(s) in DB1 are 0 (no "1" index). This means to report 125, 33 and 44 relative to place 1, 2 and 3 respectively in the output you provided.</description>
      <pubDate>Tue, 08 Aug 2023 18:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888448#M39455</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2023-08-08T18:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values by classes and format the output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888541#M39470</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB1;
input cat1 cat2 cat3 cat4 cat5 place value;
cards;
0 0 0 0 0 1 125
0 0 0 0 0 2 33
0 0 0 0 0 3 44
0 0 1 0 0 1 2
0 0 1 0 0 2 .
0 0 1 0 0 3 1
0 1 0 0 0 1 .
0 1 0 0 0 2 .
0 1 0 0 0 3 .
0 1 0 1 0 1 65
0 1 0 1 0 2 36
0 1 0 1 0 3 43
0 1 1 0 0 1 .
0 1 1 0 0 2 .
0 1 1 1 0 1 4
0 1 1 1 0 2 2
1 0 0 0 0 1 164
1 0 0 0 0 2 516
1 0 0 0 0 3 619
1 0 1 0 0 1 5
1 0 1 0 0 2 1
1 0 1 0 0 3 2
;

proc sql;
create table want as
select 0 as cat,place,sum(value) as value from DB1 where sum(cat1,cat2,cat3,cat4,cat5)=0 group by place
union
select 1,place,sum(cat1*value) from DB1 group by place
union
select 2,place,sum(cat2*value) from DB1 group by place
union
select 3,place,sum(cat3*value) from DB1 group by place
union
select 4,place,sum(cat4*value) from DB1 group by place
union
select 5,place,sum(cat5*value) from DB1 group by place
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Aug 2023 11:27:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-by-classes-and-format-the-output/m-p/888541#M39470</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-08-09T11:27:45Z</dc:date>
    </item>
  </channel>
</rss>

