<?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 in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Sum/m-p/19652#M4012</link>
    <description>PROC SQL;&lt;BR /&gt;
create table y as&lt;BR /&gt;
select sum(id) as sum_id&lt;BR /&gt;
from x&lt;BR /&gt;
where tot =1 or tot = 2;&lt;BR /&gt;
QUIT;&lt;BR /&gt;
&lt;BR /&gt;
OR&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
create table y as&lt;BR /&gt;
select sum(id) as sum_id, tot&lt;BR /&gt;
from x&lt;BR /&gt;
where tot =1 or tot = 2&lt;BR /&gt;
group by tot;&lt;BR /&gt;
QUIT;</description>
    <pubDate>Thu, 16 Apr 2009 13:49:07 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-04-16T13:49:07Z</dc:date>
    <item>
      <title>Sum</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sum/m-p/19650#M4010</link>
      <description>i have a dataset&lt;BR /&gt;
&lt;BR /&gt;
data x;&lt;BR /&gt;
input id  tot;&lt;BR /&gt;
cards;&lt;BR /&gt;
5   1&lt;BR /&gt;
6   2&lt;BR /&gt;
7     .&lt;BR /&gt;
5   1&lt;BR /&gt;
6  2&lt;BR /&gt;
9   .&lt;BR /&gt;
&lt;BR /&gt;
Now i want a new variable i want the sum of id having  1  and 2</description>
      <pubDate>Thu, 16 Apr 2009 07:16:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sum/m-p/19650#M4010</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-16T07:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: Sum</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sum/m-p/19651#M4011</link>
      <description>This kind of problem  looks like homework.&lt;BR /&gt;
&lt;BR /&gt;
Here is thus an answer but you have to read documentation&lt;BR /&gt;
about the "retain" statement to understand the first step which is calculating your results&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/onlinedoc/913/getDoc/fr/lrdict.hlp/a000214163.htm" target="_blank"&gt;http://support.sas.com/onlinedoc/913/getDoc/fr/lrdict.hlp/a000214163.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
the second datastep is showing you that the result are in the table on the last observation&lt;BR /&gt;
but understanding this step is not trivial and need a 'sum' of  practice.&lt;BR /&gt;
&lt;BR /&gt;
Andre&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data x;&lt;BR /&gt;
infile cards ; &lt;BR /&gt;
input id tot; retain one two  0;&lt;BR /&gt;
if tot=1 then one+id;&lt;BR /&gt;
if tot=2 then two+id;&lt;BR /&gt;
cards;&lt;BR /&gt;
5 1&lt;BR /&gt;
6 2&lt;BR /&gt;
7 .&lt;BR /&gt;
5 1&lt;BR /&gt;
6 2&lt;BR /&gt;
9 .&lt;BR /&gt;
run;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
set x nobs=l point=l;&lt;BR /&gt;
put one= two= ;&lt;BR /&gt;
stop;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 16 Apr 2009 08:08:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sum/m-p/19651#M4011</guid>
      <dc:creator>Andre</dc:creator>
      <dc:date>2009-04-16T08:08:54Z</dc:date>
    </item>
    <item>
      <title>Re: Sum</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sum/m-p/19652#M4012</link>
      <description>PROC SQL;&lt;BR /&gt;
create table y as&lt;BR /&gt;
select sum(id) as sum_id&lt;BR /&gt;
from x&lt;BR /&gt;
where tot =1 or tot = 2;&lt;BR /&gt;
QUIT;&lt;BR /&gt;
&lt;BR /&gt;
OR&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
create table y as&lt;BR /&gt;
select sum(id) as sum_id, tot&lt;BR /&gt;
from x&lt;BR /&gt;
where tot =1 or tot = 2&lt;BR /&gt;
group by tot;&lt;BR /&gt;
QUIT;</description>
      <pubDate>Thu, 16 Apr 2009 13:49:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sum/m-p/19652#M4012</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-16T13:49:07Z</dc:date>
    </item>
  </channel>
</rss>

