What do you mean by incredibly inefficient?
If you would like to use your arrays so that your program is shorter, you can. This decreases the amount of code to write, but would not decrease the execution time, because you're still doing 11 assignment statements.
Untested:
if last then do;
Variable= "Total" ;
do i=1 to dim(year) ;
year{i}=yearsum{i} ;
end ;
output ;
end;
As of others have mentioned, this type of wide dataset often creates the need for clunky code like this. Typically code is easier when data are structured vertically. If you had a variable for Year, and variables for Wages Retirement Medical, then you would create a Total variable as just Total=sum(Wages,Retirement,Medical).
I feel like I spent the first 5 years of my SAS programming learning how to use arrays, and then spent the second 5 years learning to recognize when my thought to use an array was an indication of a data structure problem.
... View more