<?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: merging rows in the table based on certain conditions in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/merging-rows-in-the-table-based-on-certain-conditions/m-p/825842#M35238</link>
    <description>&lt;P&gt;There could be one problem in your data: the variable cost must be numeric to be used in calculations.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Jul 2022 06:20:34 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2022-07-28T06:20:34Z</dc:date>
    <item>
      <title>merging rows in the table based on certain conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/merging-rows-in-the-table-based-on-certain-conditions/m-p/825794#M35234</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi, I'm new to SAS and I'm trying to modify a dataset. basically, I want to add certain variables up if they have the same ID and the same mon and call it sum.&lt;/P&gt;&lt;P&gt;A is the input dataset and B is the output dataset that I want. I'm not sure if SAS is able to do this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any tips would be appreciated! Thank you!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data A;
input id $ mon $ cost $;
datalines;
111 01 11.34
112 02 3.56
112 02 4.98
112 03 5.88
114 04 7.89
;
run;
data B;
input id $ mon $ sum$;
datalines;
111 01 11.34
112 02 8.54
112 03 5.88
114 04 7.89
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 22:15:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/merging-rows-in-the-table-based-on-certain-conditions/m-p/825794#M35234</guid>
      <dc:creator>LisaZ1</dc:creator>
      <dc:date>2022-07-27T22:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: merging rows in the table based on certain conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/merging-rows-in-the-table-based-on-certain-conditions/m-p/825801#M35235</link>
      <description>&lt;P&gt;Just how are we supposed to 'sum' a character variable of COST???? If your variable is actually character then you likely need to fix that and make a numeric variable to allow arithmetic on it.&lt;/P&gt;
&lt;P&gt;Assuming the $ for the input of cost is a typo (that makes it a character variable, If you want to display the value with dollar or other currency symbols you need to assign a format that does that).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;data A;
input id $ mon $ cost ;
datalines;
111 01 11.34
112 02 3.56
112 02 4.98
112 03 5.88
114 04 7.89
;

proc summary data=a nway;
   by id mon;
   var cost;
   output out=want(drop=_type_ _freq_) sum= /autoname;
run;&lt;/PRE&gt;
&lt;P&gt;I like summary for this as you can summarize many variables with&amp;nbsp; many statistics and with the option of Autoname you don't even have to spend a lot of time thinking up new variable names. The option Autoname will place a suffix of the statistic after the variable names on the VAR statement.&lt;/P&gt;
&lt;P&gt;BY group processing does require data to be sorted in the order of the variables on the statement but is a very powerful tool to process groups of records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 00:18:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/merging-rows-in-the-table-based-on-certain-conditions/m-p/825801#M35235</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-07-28T00:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: merging rows in the table based on certain conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/merging-rows-in-the-table-based-on-certain-conditions/m-p/825842#M35238</link>
      <description>&lt;P&gt;There could be one problem in your data: the variable cost must be numeric to be used in calculations.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 06:20:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/merging-rows-in-the-table-based-on-certain-conditions/m-p/825842#M35238</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-07-28T06:20:34Z</dc:date>
    </item>
    <item>
      <title>Re: merging rows in the table based on certain conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/merging-rows-in-the-table-based-on-certain-conditions/m-p/826033#M35247</link>
      <description>yeah, cost should be numeric variable. I didn't know $ means character, I thought $ is a must-have when you create data like this.&lt;BR /&gt;Thank you so much and how you did the proc summary did exactly what I need. I really appreciated that!</description>
      <pubDate>Thu, 28 Jul 2022 19:31:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/merging-rows-in-the-table-based-on-certain-conditions/m-p/826033#M35247</guid>
      <dc:creator>LisaZ1</dc:creator>
      <dc:date>2022-07-28T19:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: merging rows in the table based on certain conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/merging-rows-in-the-table-based-on-certain-conditions/m-p/826034#M35248</link>
      <description>Yeah var cost should be a numeric instead of character. I didn't know that $ means character when creating datelines. Thank you!</description>
      <pubDate>Thu, 28 Jul 2022 19:32:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/merging-rows-in-the-table-based-on-certain-conditions/m-p/826034#M35248</guid>
      <dc:creator>LisaZ1</dc:creator>
      <dc:date>2022-07-28T19:32:24Z</dc:date>
    </item>
  </channel>
</rss>

