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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register 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
  • 1060 views
  • 0 likes
  • 2 in conversation