<?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 in column by id? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188650#M265896</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have tried your method. But I still meet one small problem.&lt;/P&gt;&lt;P&gt;The sum is 38&lt;STRONG&gt;.&lt;/STRONG&gt;17. But I want the sum as 3817.&lt;/P&gt;&lt;P&gt;Can I just sum it without any comma? Or maybe I should change other numeric format?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="q.JPG" class="jive-image-thumbnail jive-image" src="https://communities.sas.com/legacyfs/online/5039_q.JPG" width="450" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 27 Feb 2014 13:10:15 GMT</pubDate>
    <dc:creator>Willy</dc:creator>
    <dc:date>2014-02-27T13:10:15Z</dc:date>
    <item>
      <title>How to sum in column by id?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188644#M265890</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello! &lt;/P&gt;&lt;P&gt;I want to sum cd34 by the same id and name the sum as OPD_cost.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;However I meet some problem while programming it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;133&amp;nbsp; proc means data= a.question sum;&lt;/P&gt;&lt;P&gt;134&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var cd34;&lt;/P&gt;&lt;P&gt;ERROR: Variable cd34 in list does not match type prescribed for this list.&lt;/P&gt;&lt;P&gt;135&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by id;&lt;/P&gt;&lt;P&gt;136&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output out = test3 sum = OPD_cost;&lt;/P&gt;&lt;P&gt;137&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;&lt;P&gt;WARNING: The data set WORK.TEST3 may be incomplete.&amp;nbsp; When this step was stopped there were 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; observations and 0 variables.&lt;/P&gt;&lt;P&gt;WARNING: Data set WORK.TEST3 was not replaced because this step was stopped.&lt;/P&gt;&lt;P&gt;NOTE: PROCEDURE MEANS used (Total process time):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the code I have tried.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;proc means data= a.question sum;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; var cd34;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; by id;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; output out = test3 sum = OPD_cost;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone tell me how to fix the problem or the right code? Thanks a lot!!!!!!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 07:48:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188644#M265890</guid>
      <dc:creator>Willy</dc:creator>
      <dc:date>2014-02-27T07:48:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum in column by id?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188645#M265891</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The error message indicates CD34 is a string not numeric.&lt;/P&gt;&lt;P&gt;what does it contain?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 09:35:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188645#M265891</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2014-02-27T09:35:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum in column by id?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188646#M265892</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It seems that variable CD34 is character.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;first transform it to numeric one: CD34_NUM = input(CD34, comma21.2);&lt;/P&gt;&lt;P&gt;instead of comma21.2 you can use some other numeric format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then what are you going to achieve?&lt;/P&gt;&lt;P&gt;table like this?&lt;/P&gt;&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sum_CD34&lt;/P&gt;&lt;P&gt;001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 100&lt;/P&gt;&lt;P&gt;002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 250&lt;/P&gt;&lt;P&gt;003&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 350&lt;/P&gt;&lt;P&gt;etc...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If this is what you want, easy way is to use proc sql;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12.800000190734863px; background-color: #ffffff;"&gt;OPD_cost&lt;/SPAN&gt; as&lt;/P&gt;&lt;P&gt;select id, sum(input(CD34, comma21.2)) as Sum_CD34&lt;/P&gt;&lt;P&gt;from &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12.800000190734863px; background-color: #ffffff;"&gt;a.question&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12.800000190734863px; background-color: #ffffff;"&gt;group by id&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12.800000190734863px; background-color: #ffffff;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12.800000190734863px; background-color: #ffffff;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 11:44:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188646#M265892</guid>
      <dc:creator>stataddict</dc:creator>
      <dc:date>2014-02-27T11:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum in column by id?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188647#M265893</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@stataddict provides a solution to deal with the convesion to numeric.&lt;/P&gt;&lt;P&gt;My question is about the contents - it is very unusual to see a column stored as text that is suitable for summing. Does it also contain non-numeric strings?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 12:25:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188647#M265893</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2014-02-27T12:25:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum in column by id?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188648#M265894</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not sure. But I think its just contain numeric. @@"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 12:56:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188648#M265894</guid>
      <dc:creator>Willy</dc:creator>
      <dc:date>2014-02-27T12:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum in column by id?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188649#M265895</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I looked to your table, all the variables are character except id...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 13:01:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188649#M265895</guid>
      <dc:creator>stataddict</dc:creator>
      <dc:date>2014-02-27T13:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum in column by id?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188650#M265896</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have tried your method. But I still meet one small problem.&lt;/P&gt;&lt;P&gt;The sum is 38&lt;STRONG&gt;.&lt;/STRONG&gt;17. But I want the sum as 3817.&lt;/P&gt;&lt;P&gt;Can I just sum it without any comma? Or maybe I should change other numeric format?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="q.JPG" class="jive-image-thumbnail jive-image" src="https://communities.sas.com/legacyfs/online/5039_q.JPG" width="450" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 13:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188650#M265896</guid>
      <dc:creator>Willy</dc:creator>
      <dc:date>2014-02-27T13:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum in column by id?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188651#M265897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here are the values of &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12.800000190734863px; background-color: #ffffff;"&gt;CD34&lt;/SPAN&gt; variable&lt;/P&gt;&lt;P&gt;00000341&lt;/P&gt;&lt;P&gt;00000919&lt;/P&gt;&lt;P&gt;00001174&lt;/P&gt;&lt;P&gt;00001383&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess comma format converts not in&amp;nbsp; a proper way.&lt;/P&gt;&lt;P&gt;So, instead of comma21.2 use only 8.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 12.800000190734863px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc sql;&lt;/P&gt;&lt;P style="font-size: 12.800000190734863px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;create table &lt;SPAN style="font-weight: inherit; font-style: inherit;"&gt;OPD_cost&lt;/SPAN&gt; as&lt;/P&gt;&lt;P style="font-size: 12.800000190734863px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;select id, sum(input(CD34, 8.)) as Sum_CD34&lt;/P&gt;&lt;P style="font-size: 12.800000190734863px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;from &lt;SPAN style="font-weight: inherit; font-style: inherit;"&gt;a.question&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12.800000190734863px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit;"&gt;group by id&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12.800000190734863px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12.800000190734863px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 13:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188651#M265897</guid>
      <dc:creator>stataddict</dc:creator>
      <dc:date>2014-02-27T13:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum in column by id?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188652#M265898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When you read a value with no decimal using and informat with a Decimal specification that's how it works.&amp;nbsp; You got what you ask for.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you remove the &lt;SPAN style="color: #ff0000;"&gt;d&lt;/SPAN&gt; from comma21.&lt;SPAN style="color: #ff0000;"&gt;2&lt;/SPAN&gt; you should get what you expect.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 13:24:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188652#M265898</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2014-02-27T13:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum in column by id?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188653#M265899</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In&lt;/P&gt;&lt;P&gt;CD34_NUM = input(CD34, comma21.2);&lt;/P&gt;&lt;P&gt;replace the format with comma21.&lt;/P&gt;&lt;P&gt;The format works like that:&lt;/P&gt;&lt;P&gt;- read in all numeric digits as a natural number&lt;/P&gt;&lt;P&gt;- if there is a number X after the dot in the format, divide by 10^X&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your numbers were converted as 1.00, 2.50, 3.50 respectively instead of 100, 250, 350&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 13:26:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188653#M265899</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2014-02-27T13:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum in column by id?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188654#M265900</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi I hope You get your answer and confirm the same .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*first subset your variable from the data set by id and cd43 ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have ;&lt;/P&gt;&lt;P&gt;set question ;&lt;/P&gt;&lt;P&gt;cd43=(input(CD34, 8.)) ;&lt;/P&gt;&lt;P&gt;keep id cd43 ;&lt;/P&gt;&lt;P&gt;run ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*then calculation by id variable ; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want ;&lt;/P&gt;&lt;P&gt;set have ;&lt;/P&gt;&lt;P&gt;by id ;&lt;/P&gt;&lt;P&gt;if first.id then Sum_cs43 = 0 ;&lt;/P&gt;&lt;P&gt;Sum_cs43 + cd43 ;&lt;/P&gt;&lt;P&gt;if last.id ;&lt;/P&gt;&lt;P&gt;drop cd43 ;&lt;/P&gt;&lt;P&gt;run ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please confirm the same&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 13:59:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-sum-in-column-by-id/m-p/188654#M265900</guid>
      <dc:creator>AjayKant</dc:creator>
      <dc:date>2014-02-27T13:59:42Z</dc:date>
    </item>
  </channel>
</rss>

