<?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 sum of a column in separate variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sum-of-a-column-in-separate-variable/m-p/584141#M166308</link>
    <description>&lt;P&gt;Hello, what's the best way to insert the sum of a column in each row of a separate variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider a data set&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA data1;
INPUT var1;
DATALINES;
1
2
3;
RUN;&lt;/PRE&gt;&lt;P&gt;I would like to generate a new variable var2 in that dataset that has the value 6 in each row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know that I can calculate the sum with PROC MEANS, then extract the value with CALL SYMPUT in another data step and then insert the value in a second data step. I could also think of some SQL join to insert the value but since this is a rather standard procedure I guess that there's an easy way and I just can't come up with it.&lt;/P&gt;</description>
    <pubDate>Tue, 27 Aug 2019 08:01:09 GMT</pubDate>
    <dc:creator>Jazzman</dc:creator>
    <dc:date>2019-08-27T08:01:09Z</dc:date>
    <item>
      <title>sum of a column in separate variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-of-a-column-in-separate-variable/m-p/584141#M166308</link>
      <description>&lt;P&gt;Hello, what's the best way to insert the sum of a column in each row of a separate variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider a data set&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA data1;
INPUT var1;
DATALINES;
1
2
3;
RUN;&lt;/PRE&gt;&lt;P&gt;I would like to generate a new variable var2 in that dataset that has the value 6 in each row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know that I can calculate the sum with PROC MEANS, then extract the value with CALL SYMPUT in another data step and then insert the value in a second data step. I could also think of some SQL join to insert the value but since this is a rather standard procedure I guess that there's an easy way and I just can't come up with it.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 08:01:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-of-a-column-in-separate-variable/m-p/584141#M166308</guid>
      <dc:creator>Jazzman</dc:creator>
      <dc:date>2019-08-27T08:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: sum of a column in separate variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-of-a-column-in-separate-variable/m-p/584142#M166309</link>
      <description>&lt;P&gt;Use the "auto remerge" feature of SAS SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select
  var1,
  sum(var1) as sum
from have1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Aug 2019 08:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-of-a-column-in-separate-variable/m-p/584142#M166309</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-27T08:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: sum of a column in separate variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-of-a-column-in-separate-variable/m-p/584144#M166311</link>
      <description>&lt;P&gt;Here is a pure data step approach&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA data1;
INPUT var1;
DATALINES;
1
2
3
;

data want;
    do until (lr1);
        set data1 end=lr1;
        sum+var1;
    end;
    do until (lr2);
        set data1 end=lr2;
        output;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Aug 2019 08:25:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-of-a-column-in-separate-variable/m-p/584144#M166311</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-27T08:25:59Z</dc:date>
    </item>
  </channel>
</rss>

