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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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