BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
umesh1
Fluorite | Level 6

MY objective is to muliply each column one by one.

for an example (1) EL_1 = FAC_1*SCORE_PD*qtr_AVG_BAL1*A_LGD_1

(2)EL_2 = FAC_2*SCORE_PD*qtr_AVG_BAL2*A_LGD_2

below is the data set. I am trying to write an array but it gives "Array subscript out of range"

I have more than 300 variables for each part such as FAC, Qtr_AVG_BaL and A_LGD

Please help me

data test;

input Fac_1 Fac_2 Fac_3 Fac_4 SCORE_PD qtr_AVG_BAL1 qtr_AVG_BAL2 qtr_AVG_BAL3 qtr_AVG_BAL4 A_LGD_1 A_LGD_2 A_LGD_3 A_LGD_4;

cards;

0.073944 0.30503 0.29877 0.32225 0.000505427 14014.3 13357.8 12688.31 12005.58 0.43729 0.40963 0.37848 0.34314

0.073944 0.30503 0.29877 0.32225 0.000505427 15512.2 14377.15 13242.1 12107.05 0.42745 0.38225 0.3293 0.26642

0.073944 0.30503 0.29877 0.32225 0.000505427 38239.72 36484.41 34707.11 32907.55 0.43753 0.41047 0.38028 0.34639

;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Would be easier if your data was in long form... Here goes

 



data test;
input Fac_1 Fac_2 Fac_3 Fac_4 SCORE_PD qtr_AVG_BAL1 qtr_AVG_BAL2 qtr_AVG_BAL3 qtr_AVG_BAL4 A_LGD_1 A_LGD_2 A_LGD_3 A_LGD_4;
array fac fac_:;
array qtr_avg qtr_avg_:;
array a_lgd a_lgd_:;
array el el_1-el_400;
do i = 1 to dim(fac);
    el{i} = score_pd * fac{i} * qtr_avg{i} * a_lgd{i};
    end;
drop i score_pd fac_: qtr_avg_: a_lgd_:;
cards;
0.073944 0.30503 0.29877 0.32225 0.000505427 14014.3 13357.8 12688.31 12005.58 0.43729 0.40963 0.37848 0.34314
0.073944 0.30503 0.29877 0.32225 0.000505427 15512.2 14377.15 13242.1 12107.05 0.42745 0.38225 0.3293 0.26642
0.073944 0.30503 0.29877 0.32225 0.000505427 38239.72 36484.41 34707.11 32907.55 0.43753 0.41047 0.38028 0.34639
;
PG

View solution in original post

2 REPLIES 2
ballardw
Super User

This might give you a start

data calc;
   set test;
   array f fac_1 - fac_4;
   array q qtr_AVG_BAL1 - qtr_AVG_BAL4;
   array a A_LGD_1  - A_LGD_4;
   array e EL_1 - EL_4;
   do i = 1 to dim(f);  /* since we know there are 4 elements in each could use "to 4"*/
                        /* but other data you may have a different number of elements and this way you don't have to change the code*/
                        /* as long as each array has the same number of elements*/
      e[i] = f[i] * score_pd * q[i] * a[i];
   end;
run

There are some other ways using variable different forms of variable lists but this is fairly flexible.

 

PGStats
Opal | Level 21

Would be easier if your data was in long form... Here goes

 



data test;
input Fac_1 Fac_2 Fac_3 Fac_4 SCORE_PD qtr_AVG_BAL1 qtr_AVG_BAL2 qtr_AVG_BAL3 qtr_AVG_BAL4 A_LGD_1 A_LGD_2 A_LGD_3 A_LGD_4;
array fac fac_:;
array qtr_avg qtr_avg_:;
array a_lgd a_lgd_:;
array el el_1-el_400;
do i = 1 to dim(fac);
    el{i} = score_pd * fac{i} * qtr_avg{i} * a_lgd{i};
    end;
drop i score_pd fac_: qtr_avg_: a_lgd_:;
cards;
0.073944 0.30503 0.29877 0.32225 0.000505427 14014.3 13357.8 12688.31 12005.58 0.43729 0.40963 0.37848 0.34314
0.073944 0.30503 0.29877 0.32225 0.000505427 15512.2 14377.15 13242.1 12107.05 0.42745 0.38225 0.3293 0.26642
0.073944 0.30503 0.29877 0.32225 0.000505427 38239.72 36484.41 34707.11 32907.55 0.43753 0.41047 0.38028 0.34639
;
PG

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 2 replies
  • 998 views
  • 0 likes
  • 3 in conversation