BookmarkSubscribeRSS Feed
jdk123
Calcite | Level 5
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
1 REPLY 1
Peter_C
Rhodochrosite | Level 12
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

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore Now →
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1523 views
  • 0 likes
  • 2 in conversation