<?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 by column with same row value on other variable , not using proc in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum-by-column-with-same-row-value-on-other-variable-not-using/m-p/607242#M176462</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/301245"&gt;@AlohaHi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't want to use a PROC, you can use the following code, assuming the dataset is sorted by Var1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input Var1 $ Var2;
	cards;
A 3
A 20
B 1
C 4
C 5
;
run; 

data want;
	set have;
	by Var1;
	
	if first.var1 then Var3 = 0;
	Var3 + Var2;
	
	if last.var1 then output;
	
	drop var2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 26 Nov 2019 09:32:46 GMT</pubDate>
    <dc:creator>ed_sas_member</dc:creator>
    <dc:date>2019-11-26T09:32:46Z</dc:date>
    <item>
      <title>Sum by column with same row value on other variable , not using proc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-by-column-with-same-row-value-on-other-variable-not-using/m-p/607240#M176460</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;it may or may not sound easy and not even sure u can understand what I am trying to do.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question is that "without using proc"&lt;/P&gt;&lt;P&gt;and if my data table is shown like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Var1 Var2&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is it possible to sum column values with same var1 value,&lt;/P&gt;&lt;P&gt;which means 3+20 because they got Same Var1 value A&lt;/P&gt;&lt;P&gt;and 4+5 for C,&lt;/P&gt;&lt;P&gt;that makes new variable Var3 on the table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if I just used&lt;/P&gt;&lt;P&gt;Var3 = Var3+Var2;&lt;/P&gt;&lt;P&gt;retain Var3 0;&lt;/P&gt;&lt;P&gt;it would just give the whole sum of numbers no matter what value they've got on Var1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 09:26:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-by-column-with-same-row-value-on-other-variable-not-using/m-p/607240#M176460</guid>
      <dc:creator>AlohaHi</dc:creator>
      <dc:date>2019-11-26T09:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: Sum by column with same row value on other variable , not using proc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-by-column-with-same-row-value-on-other-variable-not-using/m-p/607241#M176461</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/301245"&gt;@AlohaHi&lt;/a&gt;&amp;nbsp;Hi and welcome to the SAS Community &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to control your By Groups and do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Var1 $ Var2;
datalines;
A 3
A 20
B 1
C 4
C 5
;

data want;
    set have;
    by Var1;
    if first.Var1 then Var3=0;
    Var3+Var2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Nov 2019 09:30:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-by-column-with-same-row-value-on-other-variable-not-using/m-p/607241#M176461</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-26T09:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: Sum by column with same row value on other variable , not using proc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-by-column-with-same-row-value-on-other-variable-not-using/m-p/607242#M176462</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/301245"&gt;@AlohaHi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't want to use a PROC, you can use the following code, assuming the dataset is sorted by Var1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input Var1 $ Var2;
	cards;
A 3
A 20
B 1
C 4
C 5
;
run; 

data want;
	set have;
	by Var1;
	
	if first.var1 then Var3 = 0;
	Var3 + Var2;
	
	if last.var1 then output;
	
	drop var2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Nov 2019 09:32:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-by-column-with-same-row-value-on-other-variable-not-using/m-p/607242#M176462</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-11-26T09:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Sum by column with same row value on other variable , not using proc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-by-column-with-same-row-value-on-other-variable-not-using/m-p/607243#M176463</link>
      <description>&lt;P&gt;is it not possible to do within one data step?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 09:32:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-by-column-with-same-row-value-on-other-variable-not-using/m-p/607243#M176463</guid>
      <dc:creator>AlohaHi</dc:creator>
      <dc:date>2019-11-26T09:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: Sum by column with same row value on other variable , not using proc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-by-column-with-same-row-value-on-other-variable-not-using/m-p/607244#M176464</link>
      <description>&lt;P&gt;It is 1 data step? The first one simply creates the data to work with.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 09:34:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-by-column-with-same-row-value-on-other-variable-not-using/m-p/607244#M176464</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-26T09:34:08Z</dc:date>
    </item>
  </channel>
</rss>

