@sas_user_1001 wrote:
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.
My suggestion was based on your sample data, implemented like this:
data have;
input Year Widgets CAGR;
cards;
2021 93 .
2022 95 .
2023 100 0.03
;
Maybe you have Year values which are in fact datetime 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 Widgets may become very large.
Here is an example:
data have;
input Year :b8601dt. Widgets CAGR;
format Year dtyear.;
cards;
1948 93 .
1949 95 .
1950 100 0.03
;
So, make sure you know your data (Maxim 3) -- with a focus on the last observation:
data _null_;
set have nobs=n point=n;
put (Year Widgets CAGR)(=best16.);
stop;
run;
Important question: What does the above DATA _NULL_ step write to the log for your real "HAVE" dataset?
For the 1948-1950 mock-up data above it yields:
Year=-315532800 Widgets=100 CAGR=0.03
and the apparent datetime value of variable Year requires a modified approach:
data want;
set have end=last;
output;
if last & year>.z then do while(year(datepart(year))<2030);
year=intnx('dtyear',year,1,'s');
widgets=widgets*(1+CAGR);
output;
end;
run;
Similarly, if variable Year contains SAS date values, you'll need a different modification:
...
if last & year>.z then do while(year(year)<2030);
year=intnx('year',year,1,'s');
...
The inserted condition year>.z, i.e., "year is not missing," is important because, unlike the original sum statement year+1, the assignment statement year=intnx(...) would create another missing value from a missing year 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) .z in the IF condition by a reasonable lower-bound year or datetime or date value, respectively, as a safeguard against nonsensical Year values such as -1E99.
... View more