<?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 How do I create a calculated column in an existing dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-calculated-column-in-an-existing-dataset/m-p/438296#M109260</link>
    <description>&lt;P&gt;Week Sales Cum_Sales&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 160&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 390&amp;nbsp; &amp;nbsp; &amp;nbsp; 160&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 800&amp;nbsp; &amp;nbsp; &amp;nbsp; 550&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 995&amp;nbsp; &amp;nbsp; &amp;nbsp;1350&lt;BR /&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1250&amp;nbsp; &amp;nbsp; 2345&lt;BR /&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1630&amp;nbsp; &amp;nbsp; 3595&lt;BR /&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1750&lt;BR /&gt;8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2000&lt;BR /&gt;9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2250&lt;BR /&gt;10&amp;nbsp; &amp;nbsp; &amp;nbsp;2500&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The columns week and sales are provided in the dataset. I am creating a new column called cumulative_sales where the first entry is always zero and the consecutive entries are the sum of sales one week before that&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data B2;&lt;BR /&gt;set B2;&lt;BR /&gt;by week;&lt;BR /&gt;if first.week then cumulative_sales=0;&lt;BR /&gt;cumulative_sales = cumulative_sales + sales;&lt;BR /&gt;if last.week then output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please mention the corrections in the code&lt;/P&gt;</description>
    <pubDate>Sun, 18 Feb 2018 21:34:07 GMT</pubDate>
    <dc:creator>adityal2810</dc:creator>
    <dc:date>2018-02-18T21:34:07Z</dc:date>
    <item>
      <title>How do I create a calculated column in an existing dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-calculated-column-in-an-existing-dataset/m-p/438296#M109260</link>
      <description>&lt;P&gt;Week Sales Cum_Sales&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 160&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 390&amp;nbsp; &amp;nbsp; &amp;nbsp; 160&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 800&amp;nbsp; &amp;nbsp; &amp;nbsp; 550&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 995&amp;nbsp; &amp;nbsp; &amp;nbsp;1350&lt;BR /&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1250&amp;nbsp; &amp;nbsp; 2345&lt;BR /&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1630&amp;nbsp; &amp;nbsp; 3595&lt;BR /&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1750&lt;BR /&gt;8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2000&lt;BR /&gt;9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2250&lt;BR /&gt;10&amp;nbsp; &amp;nbsp; &amp;nbsp;2500&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The columns week and sales are provided in the dataset. I am creating a new column called cumulative_sales where the first entry is always zero and the consecutive entries are the sum of sales one week before that&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data B2;&lt;BR /&gt;set B2;&lt;BR /&gt;by week;&lt;BR /&gt;if first.week then cumulative_sales=0;&lt;BR /&gt;cumulative_sales = cumulative_sales + sales;&lt;BR /&gt;if last.week then output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please mention the corrections in the code&lt;/P&gt;</description>
      <pubDate>Sun, 18 Feb 2018 21:34:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-calculated-column-in-an-existing-dataset/m-p/438296#M109260</guid>
      <dc:creator>adityal2810</dc:creator>
      <dc:date>2018-02-18T21:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a calculated column in an existing dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-calculated-column-in-an-existing-dataset/m-p/438297#M109261</link>
      <description>&lt;P&gt;Here, you're increasing the cumulative sales and then outputting.&amp;nbsp; You need to output first:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;cumulative_sales + sales;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Feb 2018 21:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-calculated-column-in-an-existing-dataset/m-p/438297#M109261</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-18T21:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a calculated column in an existing dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-calculated-column-in-an-existing-dataset/m-p/438346#M109277</link>
      <description>&lt;P&gt;And using "by week" is only necessary, if you have multiple observations for one week.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2018 07:11:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-calculated-column-in-an-existing-dataset/m-p/438346#M109277</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-02-19T07:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a calculated column in an existing dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-calculated-column-in-an-existing-dataset/m-p/438355#M109281</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;options missing=0;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;x=lag(sales);&lt;BR /&gt;cum_sales+x;&lt;BR /&gt;drop x;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2018 09:13:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-calculated-column-in-an-existing-dataset/m-p/438355#M109281</guid>
      <dc:creator>srinath3111</dc:creator>
      <dc:date>2018-02-19T09:13:05Z</dc:date>
    </item>
  </channel>
</rss>

