Hi, I have worked with SAS for basic tasks and analysis in the past, but I am inexperienced with arrays and do loops. I am having trouble figuring out how to derive two subscores (sums) from data that is arranged as follows: One variable determines whether a given event is interpreted as being positive or negative ( a value of 1 = the event had a positive effect, and a value of 0 means the event in question had a negative effect). Then there is another corresponding question that asks the subject to rate the magnitude of the positive or negative event (on a scale of 0 to 3 where 0 means very slight or no effect, and 3 means the positive or negative event had a great effect). In other words, one variable (e.g. “q1_type”) tells you the affective direction/interpretation (positive or negative) and one corresponding variable (e.g. “q1_effect_mag”) tells you the magnitude of the positive or negative. Overall, I’m trying to sum up all the magnitudes of events that were considered positive to derive a positive sum, and also sum up all the magnitudes of events that were considered negative to derive a negative sum. I have the following code that is giving me some problems: data test2; set test1; array arr_A q1_type q2_type q3_type q4_type q5_type q6_type q7_type q8_type q9_type q10_type q11_type q12_type q13_type q14_type q15_type; array arr_B q1_effect_mag q2_effect_mag q3_effect_mag q4_effect_mag q5_effect_mag q6_effect_mag q7_effect_mag q8_effect_mag q9_effect_mag q10_effect_mag q11_effect_mag q12_effect_mag q13_effect_mag q14_effect_mag q15_effect_mag; positive_sum_subscale = 0; negative_sum_subscale = 0; do i = 1 to dim(arr_A); if arr_A(i) in (1) then positive_sum_subscale = positive_sum_subscale + arr_B(i); if arr_A(i) in (0) then negative_sum_subscale = negative_sum_subscale +arr_B(i); end; run; This code is giving me some values which don’t add up correctly and some missing values for either the positive or negative subscales. Is there a better/easier way to compute these scores than what I am trying at the moment? I am using SAS 9.4 Thank you
... View more