## Array problem

Solved
Occasional Contributor
Posts: 18

# Array problem

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;

Accepted Solutions
Solution
‎02-10-2016 04:13 PM
Esteemed Advisor
Posts: 5,535

## Re: Array problem

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

All Replies
Super User
Posts: 13,563

## Re: Array problem

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.

Solution
‎02-10-2016 04:13 PM
Esteemed Advisor
Posts: 5,535

## Re: Array problem

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
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
• 2 replies
• 229 views
• 0 likes
• 3 in conversation