DATA Step, Macro, Functions and more

how to position the columns in the same observation

Reply
Occasional Contributor
Posts: 18

how to position the columns in the same observation

for instance:

one of the observation from the datasets:

total of 60 columns
col1 col2 col3 col4....col60.

i would like to perform the calculations for the last three columns, such as col58 col59 col60.

the total of the columns is changing. how can i calculate the total of col58..col60
Valued Guide
Posts: 2,177

Re: how to position the columns in the same observation

in a data step I would define an array using the : (colon) suffix to include all the colXX variables and just accumulate the last 3 like
Array cols(*) col: ;
last3 = 0 ;
do idx = dim(cols) to dim(cols)-2;
last3+cols( idx);
end;

Then no matter how many COLxx columns are present only the last 3 are summed
Ask a Question
Discussion stats
  • 1 reply
  • 120 views
  • 0 likes
  • 2 in conversation