What you apparently want is code that looks like this:
data want;
set values;
seq1 = sum(score1 ,score2 ,score3 ,score4 ,score5 ,score6 ,score7 ,score8 );
seq2 = sum(score1 ,score2 ,score3 ,score4 );
seq3 = sum(score1 ,score3 ,score6 ,score8 );
seq4 = sum(score3 ,score4 ,score7 );
run;
You can use a DATA _NULL_ step reading dataset SEQ to produce that code in a temporary file, which can then be INCLUDED in a subsequent DATA WANT step, as in:
filename sumcode temp;
data _null_;
set seq;
array sdummies {*} s1-s8 ;
file sumcode;
put seqnames '= sum(' @;
do i=1 to dim(sdummies);
if sdummies{i}=1 then put 'score' i ',' @;
end;
put + (-1) ');';
run;
data want;
set values;
%include sumcode / source2 ;
run;
The primary tool used here is the trailing @ used in the PUT statements, which holds the output column pointer in place, waiting for the next PUT statement. The last PUT has the pointer control '+ (-1)' which moves the pointer back one character, in order to replace the troublesome unnecessary comma appended to the last variable name with a closing paren and a semi-colon.
This program is untested in the absence of sample data in the form of working DATA steps.
I see other responders have utilized the character variable SEQ, instead of the S1 through S8 variables that I used. If those variables are not available, then change the DATA _NULL_ step to:
filename sumcode temp;
data _null_;
set seq;
file sumcode;
put seqnames '= sum(' @;
do i=1 to countw(seq);
addend=cats('score',scan(seq,i)) ;
if i<countw(seq) then addend=cats(addend,',');
put addend @;
end;
put ');';
run;
... View more