<?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: Forecasting with a growth rate in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Forecasting-with-a-growth-rate/m-p/920540#M41251</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/463968"&gt;@sas_user_1001&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have end=last;
output;
if last then do while(year&amp;lt;2030);
  year+1;
  widgets=widgets*(1+CAGR);
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Dataset WANT will contain everything from dataset HAVE and then continue until YEAR=2030 using the value of CAGR from the last observation of HAVE.&lt;/P&gt;</description>
    <pubDate>Sat, 16 Mar 2024 08:58:05 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2024-03-16T08:58:05Z</dc:date>
    <item>
      <title>Forecasting with a growth rate</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Forecasting-with-a-growth-rate/m-p/920529#M41248</link>
      <description>&lt;P&gt;I have a table of annual data. For simplicity, column 1 is the year 2000 - 2023, column 2 is widgets produced for each of those years, and in column 3 I have just one value the CAGR for the final year of my data. The last three rows appear as follows:&lt;/P&gt;&lt;P&gt;Year&amp;nbsp; Widgets&amp;nbsp; &amp;nbsp;CAGR&lt;/P&gt;&lt;P&gt;2021&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;93&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;2022&amp;nbsp; &amp;nbsp; &amp;nbsp; 95&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;2023&amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.03&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I would like to do is forecast widgets produced annually through 2030. Thus, using my final value for 2023 and the growth rate (e.g., 100*(1+0.003) I can get a forecast for 2024. This should give me a forecasted value of 103. Next, for 2025, I would like to take the preceding value in 2024 and multiply that by the CAGR; thus 103*(1+0.03). I want to continue this process all the way through 2030. I am a bit stuck on how to best approach this in SAS and would appreciate any advice. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2024 02:11:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Forecasting-with-a-growth-rate/m-p/920529#M41248</guid>
      <dc:creator>sas_user_1001</dc:creator>
      <dc:date>2024-03-16T02:11:53Z</dc:date>
    </item>
    <item>
      <title>Re: Forecasting with a growth rate</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Forecasting-with-a-growth-rate/m-p/920540#M41251</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/463968"&gt;@sas_user_1001&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have end=last;
output;
if last then do while(year&amp;lt;2030);
  year+1;
  widgets=widgets*(1+CAGR);
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Dataset WANT will contain everything from dataset HAVE and then continue until YEAR=2030 using the value of CAGR from the last observation of HAVE.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2024 08:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Forecasting-with-a-growth-rate/m-p/920540#M41251</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-03-16T08:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: Forecasting with a growth rate</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Forecasting-with-a-growth-rate/m-p/920577#M41256</link>
      <description>&lt;P&gt;Thanks for your suggestion. For some reason I am getting an insufficient space error when I run the code. It takes a very long time to run before the error pops up, so I'm wondering if something is getting stuck in a perpetual loop? I will try and take another crack at this on Monday. Cheers.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Mar 2024 02:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Forecasting-with-a-growth-rate/m-p/920577#M41256</guid>
      <dc:creator>sas_user_1001</dc:creator>
      <dc:date>2024-03-17T02:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: Forecasting with a growth rate</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Forecasting-with-a-growth-rate/m-p/920579#M41257</link>
      <description>&lt;P&gt;Show the EXACT code that you ran.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do while is one of the things if done incorrectly will run forever but we need to see what you actually run.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Mar 2024 03:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Forecasting-with-a-growth-rate/m-p/920579#M41257</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-17T03:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: Forecasting with a growth rate</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Forecasting-with-a-growth-rate/m-p/920598#M41261</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/463968"&gt;@sas_user_1001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your suggestion. For some reason I am getting an insufficient space error when I run the code. It takes a very long time to run before the error pops up, so I'm wondering if something is getting stuck in a perpetual loop? I will try and take another crack at this on Monday. Cheers.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;My suggestion was based on your sample data, implemented like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Year Widgets CAGR;
cards;
2021 93 .
2022 95 .
2023 100 0.03
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe you have &lt;FONT face="courier new,courier"&gt;Year&lt;/FONT&gt; values which are in fact &lt;EM&gt;datetime&lt;/EM&gt; values and the pivotal year in the last observation is in the 1950s or earlier? Then, indeed, the DO-WHILE loop would create a lot of observations and the (exponentially growing) value of variable&amp;nbsp;&lt;FONT face="courier new,courier"&gt;Widgets&lt;/FONT&gt; may become &lt;EM&gt;very&lt;/EM&gt; large.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Year :b8601dt. Widgets CAGR;
format Year dtyear.;
cards;
1948 93 .
1949 95 .
1950 100 0.03
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, make sure you know your data (&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_blank" rel="noopener"&gt;Maxim 3&lt;/A&gt;) -- with a focus on the last observation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set have nobs=n point=n;
put (Year Widgets CAGR)(=best16.);
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;EM&gt;Important question:&lt;/EM&gt; What does the above DATA _NULL_ step write to the log for your real "HAVE" dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the 1948-1950 mock-up data above it yields:&lt;/P&gt;
&lt;PRE&gt;Year=-315532800 Widgets=100 CAGR=0.03&lt;/PRE&gt;
&lt;P&gt;and the apparent &lt;EM&gt;datetime&lt;/EM&gt; value of variable&amp;nbsp;&lt;FONT face="courier new,courier"&gt;Year&lt;/FONT&gt; requires a modified approach:&lt;/P&gt;
&lt;PRE&gt;data want;
set have end=last;
output;
if last &lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;&amp;amp; year&amp;gt;.z&lt;/STRONG&gt;&lt;/FONT&gt; then do while(&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;year(datepart(year))&lt;/STRONG&gt;&lt;/FONT&gt;&amp;lt;2030);
  year&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;=intnx('dtyear',year,1,'s')&lt;/STRONG&gt;&lt;/FONT&gt;;
  widgets=widgets*(1+CAGR);
  output;
end;
run;&lt;/PRE&gt;
&lt;P&gt;Similarly, if variable &lt;FONT face="courier new,courier"&gt;Year&lt;/FONT&gt; contains SAS &lt;EM&gt;date&lt;/EM&gt; values, you'll need a different modification:&lt;/P&gt;
&lt;PRE&gt;...
if last&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt; &amp;amp; year&amp;gt;.z&lt;/STRONG&gt;&lt;/FONT&gt; then do while(&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;year(year)&lt;/FONT&gt;&lt;/STRONG&gt;&amp;lt;2030);
  year&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;=intnx('year',year,1,'s')&lt;/STRONG&gt;&lt;/FONT&gt;;
...&lt;/PRE&gt;
&lt;P&gt;The inserted condition &lt;FONT face="courier new,courier"&gt;year&amp;gt;.z&lt;/FONT&gt;, i.e., "&lt;FONT face="courier new,courier"&gt;year&lt;/FONT&gt; is not missing," is important because, unlike the original sum statement &lt;FONT face="courier new,courier"&gt;year+1&lt;/FONT&gt;, the assignment statement &lt;FONT face="courier new,courier"&gt;year=intnx(&lt;/FONT&gt;...&lt;FONT face="courier new,courier"&gt;)&lt;/FONT&gt;&amp;nbsp;would create another missing value from a missing &lt;FONT face="courier new,courier"&gt;year&lt;/FONT&gt; value. Thus, the WHILE condition would always be met, leading to an infinite loop. To make the code even more robust, you could replace (the special missing value) &lt;FONT face="courier new,courier"&gt;.z&lt;/FONT&gt;&amp;nbsp;in the IF condition by a reasonable lower-bound year or datetime or date value, respectively, as a safeguard against nonsensical &lt;FONT face="courier new,courier"&gt;Year&lt;/FONT&gt; values such as &lt;FONT face="courier new,courier"&gt;-1E99&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Mar 2024 12:05:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Forecasting-with-a-growth-rate/m-p/920598#M41261</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-03-17T12:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: Forecasting with a growth rate</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Forecasting-with-a-growth-rate/m-p/920743#M41269</link>
      <description>&lt;P&gt;Thank you for your detailed response. I read through it this morning and I was able to troubleshoot the error. I think it was probably a combination of two things on my end. (1) my "Year" column was actually char and not numeric, which I believe confuses the counter part of the code; (2) I think I may have had a variable name issue. I have worked through a number of iterations this morning, and it works now, so thank you for your help! I am going to mark your original answer as the solution, because I believe under the right conditions it should have worked the first time. Cheers.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 15:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Forecasting-with-a-growth-rate/m-p/920743#M41269</guid>
      <dc:creator>sas_user_1001</dc:creator>
      <dc:date>2024-03-18T15:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: Forecasting with a growth rate</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Forecasting-with-a-growth-rate/m-p/920757#M41270</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/463968"&gt;@sas_user_1001&lt;/a&gt;, for explaining the issue. After your first reply I had also thought about a potential type mismatch, but then was relieved to see that if &lt;FONT face="courier new,courier"&gt;Year&lt;/FONT&gt;&amp;nbsp;was&amp;nbsp; a character variable, the sum statement &lt;FONT face="courier new,courier"&gt;year+1&lt;/FONT&gt; would terminate the DATA step with an error message&lt;/P&gt;
&lt;PRE&gt;378     year+1;
&lt;FONT color="#FF0000"&gt;        -
        400
ERROR 400-185: The SUM statement requires numeric expression.
&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;rather than lead to an infinite loop. Sorry for "causing" that some other way.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 15:49:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Forecasting-with-a-growth-rate/m-p/920757#M41270</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-03-18T15:49:51Z</dc:date>
    </item>
  </channel>
</rss>

