I am touching up some SAS code I wrote and found a chunk of code I wish to execute more effectively. I have a time-series data set called 'Forecasts' which just consists of date and the 'Forecast' variable for a given date.
I wrote a simple block of code to take this variable and basically chop it up into a series of variables, each one representing one date:
data forecasts;
set forecasts;
obs=_n_;
array r(241);
do i=1 to dim(r);
if obs=i then r(i)=Forecast;
end; drop i; drop obs; drop forecast;
run;
However, the 'r(241)' part of this code really annoys me. I already have a macro variable which corresponds to the number of times I need to perform this operation (called 'n'), and I would rather just plug it into the array proclamation directly, something like:
array r(&n)
etc.
However macro variables are obviously considered text, so even when I managed to import the macro variable into the data step, variants r(&n) doesn't work because it doesn't read 'n' as a numeric. Outside of wrapping this entire data step into a broader macro, how can I pull 'n' into the data step then convert it to a numeric so this operation works?