How to calculate (sum) from multiple variable thru loop, if variable are not in sequential order
Posted by
Satish on
Jul 13, 2022; 12:13pm
URL: http://spssx-discussion.165.s1.nabble.com/How-to-calculate-sum-from-multiple-variable-thru-loop-if-variable-are-not-in-sequential-order-tp5741009.html
Respected member,
I have a query please help me on this as soon as possible.
I have set of 314 variable starting from Q6I_T_1 to Q6I_T_246 and Q6I_T_1001 to Q6I_T_1068. But all these variables are not in order because we have other set of variable in between. I have tried below mentioned syntax and it's working fine if I am putting range around 100. when i am putting range till 186 or more it's not calculating anything.
note : I have few varibles where data is missing.
Can you help me how i can get total sum of all variables starting from Q6I_T_1 to Q6I_T_1068 . it will great help.
COMPUTE total_share1 = 0.
DEFINE !TSum ().
!DO !t = 1 !TO 100.
!LET !XSum = !CONCAT("Q6I_T_",!t).
!LET !invars = !CONCAT("sum(",!XSum,")").
COMPUTE total_share1 = total_share1+!invars.
!DOEND.
!ENDDEFINE.
!TSum.
EXECUTE.
thanks in advance.
Regards
Test.savSAT