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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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