I've got a data file that has five test scores for 20 students. Each test score has its own passing grade of 68, 70, 72, 74, 76 respectively.
I read in this data from a .dat file but need to calculate the number of tests passed by each student. This is fairly easy to do using if statements, but I need to utilize arrays here. So my code looks like
data test_scores;
infile '---------------------------------';
input t1 t2 t3 t4 t5;
array test_scores{5} t1 t2 t3 t4 t5;
do n=1 to 5;
if tests[i] =
This is where I am stuck. I realize I can say that if the index is 1 and test score is greater than 68, add to the accumulator variable tests_passed and then do for all 5 but that seems redundant and where I started with. Any help would be appreciated!
Since your score cutoffs are evenly spaced, you could do:
do n=1 to 5;
if test_scores[n] >= 66 + 2 * n
But that's not very extensible, so perhaps the better method is to have an array of cutoff scores:
array pass_cutoff{5} 68 70 72 74 76;
do n=1 to 5;
if test_scores[n] >= pass_cutoff[n]
This way, if a cutoff changes, you just update the array initialization, and everything still works.