<?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: Multiplying a row by another rows previous value in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Multiplying-a-row-by-another-rows-previous-value/m-p/767431#M30757</link>
    <description>&lt;P&gt;Apologies, I'll clarify.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input year ratio have have2 want;
cards;
2021 1 5 . 5
2022 2 . 5 10
2023 3 . 10 30
2024 4 . 30 120
2025 5 . 120 600
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I've updated the sample code.&amp;nbsp;I only have ratio and have, I'm trying to generate have2, and finally want. It's been a while since I've written a sas code, so I'm a bit rusty.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To elaborate further,&amp;nbsp;&lt;/P&gt;&lt;P&gt;for 2022, I want to multiply, ratio2022 with have2021&lt;/P&gt;&lt;P&gt;for 2023, I want to multiply, ratio 2023 with have 2022 so on.&lt;/P&gt;</description>
    <pubDate>Mon, 13 Sep 2021 14:37:42 GMT</pubDate>
    <dc:creator>ted_lariat</dc:creator>
    <dc:date>2021-09-13T14:37:42Z</dc:date>
    <item>
      <title>Multiplying a row by another rows previous value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiplying-a-row-by-another-rows-previous-value/m-p/767423#M30755</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I'm trying to multiply my &lt;STRONG&gt;ratio&lt;/STRONG&gt; column with lagged &lt;STRONG&gt;have&lt;/STRONG&gt; value to get to the&amp;nbsp;&lt;STRONG&gt;want&lt;/STRONG&gt; colum. What approach should I take?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input year ratio have want;
cards;
2021 1 5  5
2022 2 . 10
2023 3 . 30
2024 4 . 120
2025 5 . 600
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you for your time.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 14:15:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiplying-a-row-by-another-rows-previous-value/m-p/767423#M30755</guid>
      <dc:creator>ted_lariat</dc:creator>
      <dc:date>2021-09-13T14:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplying a row by another rows previous value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiplying-a-row-by-another-rows-previous-value/m-p/767428#M30756</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;...&amp;nbsp;&lt;SPAN&gt;multiply my&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;ratio&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;column with lagged&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;have&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;value ...&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So doing the math, on row 4 the lagged have value would have to be 30. I don't really see how the lagged have value gets to be 30. Please explain further.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 14:31:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiplying-a-row-by-another-rows-previous-value/m-p/767428#M30756</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-13T14:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplying a row by another rows previous value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiplying-a-row-by-another-rows-previous-value/m-p/767431#M30757</link>
      <description>&lt;P&gt;Apologies, I'll clarify.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input year ratio have have2 want;
cards;
2021 1 5 . 5
2022 2 . 5 10
2023 3 . 10 30
2024 4 . 30 120
2025 5 . 120 600
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I've updated the sample code.&amp;nbsp;I only have ratio and have, I'm trying to generate have2, and finally want. It's been a while since I've written a sas code, so I'm a bit rusty.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To elaborate further,&amp;nbsp;&lt;/P&gt;&lt;P&gt;for 2022, I want to multiply, ratio2022 with have2021&lt;/P&gt;&lt;P&gt;for 2023, I want to multiply, ratio 2023 with have 2022 so on.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 14:37:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiplying-a-row-by-another-rows-previous-value/m-p/767431#M30757</guid>
      <dc:creator>ted_lariat</dc:creator>
      <dc:date>2021-09-13T14:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplying a row by another rows previous value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiplying-a-row-by-another-rows-previous-value/m-p/767448#M30759</link>
      <description>&lt;P&gt;Why is the value of HAVE missing for all but the first observation?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input year ratio have expect;
cards;
2021 1 5  5
2022 2 . 10
2023 3 . 30
2024 4 . 120
2025 5 . 600
;

data want;
  set have;
  retain prod;
  if _n_=1 then prod=have;
  else prod=prod*ratio;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What if RATIO on the first observation is not 1 what do you want for the new running product variable?&amp;nbsp; If you want it to be HAVE*RATIO then remove the ELSE keyword.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 15:40:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiplying-a-row-by-another-rows-previous-value/m-p/767448#M30759</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-13T15:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplying a row by another rows previous value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiplying-a-row-by-another-rows-previous-value/m-p/767610#M30775</link>
      <description>thanks, it is working like a charm. much appreciated.</description>
      <pubDate>Tue, 14 Sep 2021 05:37:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiplying-a-row-by-another-rows-previous-value/m-p/767610#M30775</guid>
      <dc:creator>ted_lariat</dc:creator>
      <dc:date>2021-09-14T05:37:06Z</dc:date>
    </item>
  </channel>
</rss>

