<?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 one step ahead in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Multiplying-one-step-ahead/m-p/921205#M41325</link>
    <description>&lt;P&gt;It is probably easiest to make a NEW variable so you can retain its value (and it the retained value will be overwritten when you read in the next observation.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input year x y;
cards;
2000 . 5
2001 2 .
2002 3 .
2003 4 .
;

data want;
  set have;
  retain newy ;
  newy=coalesce(y,x*newy);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    year    x    y    newy

 1     2000    .    5       5
 2     2001    2    .      10
 3     2002    3    .      30
 4     2003    4    .     120
&lt;/PRE&gt;</description>
    <pubDate>Wed, 20 Mar 2024 22:53:56 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-03-20T22:53:56Z</dc:date>
    <item>
      <title>Multiplying one step ahead</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiplying-one-step-ahead/m-p/921200#M41322</link>
      <description>&lt;P&gt;I'm trying to figure out the best way to multiply two data points that are adjacent. A simplified version of my data is as follows:&lt;/P&gt;&lt;P&gt;year&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; x&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;y&lt;/P&gt;&lt;P&gt;2000&amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;2001&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;2002&amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;2003&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to multiply 5x2 to produce 10 in column y for the year 2001. Similarly, I want to multiply 3 by the new value 10 in column y, to produce 30 in the year 2002. Finally, I want to multiply 4 by the new value of 30 to produce 120 in the year 2003. Any help is much appreciated. Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 22:24:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiplying-one-step-ahead/m-p/921200#M41322</guid>
      <dc:creator>sas_user_1001</dc:creator>
      <dc:date>2024-03-20T22:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplying one step ahead</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiplying-one-step-ahead/m-p/921203#M41324</link>
      <description>&lt;P&gt;Please note the first data step as a way to provide existing data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
   input year        x       y;
datalines;
2000      .        5
2001      2         .
2002     3         .
2003     4         .
;

data want;
   set have;
   retain ly;
   if _n_ =1 then ly=y;
   else ly= ly*x;
run;&lt;/PRE&gt;
&lt;P&gt;I'm placing the value of result into a new variable LY so the value persist across data step iterations with the RETAIN statement. If you attempt to Retain a variable in the source data set it gets reset each time a new observation is read from the source.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are going to have groups of records that need to "reset" the Ly, such as when apply this algorithm to person, geography, time or similar values you need to include more details as likely BY group processing with the First and Last options will come into play.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 22:46:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiplying-one-step-ahead/m-p/921203#M41324</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-20T22:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplying one step ahead</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiplying-one-step-ahead/m-p/921205#M41325</link>
      <description>&lt;P&gt;It is probably easiest to make a NEW variable so you can retain its value (and it the retained value will be overwritten when you read in the next observation.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input year x y;
cards;
2000 . 5
2001 2 .
2002 3 .
2003 4 .
;

data want;
  set have;
  retain newy ;
  newy=coalesce(y,x*newy);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    year    x    y    newy

 1     2000    .    5       5
 2     2001    2    .      10
 3     2002    3    .      30
 4     2003    4    .     120
&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Mar 2024 22:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiplying-one-step-ahead/m-p/921205#M41325</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-20T22:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplying one step ahead</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Multiplying-one-step-ahead/m-p/921209#M41326</link>
      <description>Thanks--I like this solution as I have not used the coalesce function before.</description>
      <pubDate>Thu, 21 Mar 2024 00:06:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Multiplying-one-step-ahead/m-p/921209#M41326</guid>
      <dc:creator>sas_user_1001</dc:creator>
      <dc:date>2024-03-21T00:06:55Z</dc:date>
    </item>
  </channel>
</rss>

