<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to score elements of an array specified in another dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-score-elements-of-an-array-specified-in-another-dataset/m-p/961543#M374856</link>
    <description>&lt;P&gt;Make sure your scoring dataset has _NAME_ and _TYPE_ variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data seq ;
  _type_='SCORE';
  input description:$20. _name_ $ score1-score8;
cards;
1,2,3,4,5,6,7,8 seq1 1 1 1 1 1 1 1 1
1,2,3,4         seq2 1 1 1 1 0 0 0 0
1,3,6,8         seq3 1 0 1 0 0 1 0 1
3,4,7           seq4 0 0 1 1 0 0 1 0
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now let's make up a few observations of data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data values;
  input id score1-score8;
cards;
1 1 2 3 4 5 6 7 8
2 0 1 0 1 0 1 0 1
3 1 1 1 1 1 1 1 1
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then score it&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc score data=values score=seq out=want;
  var score1-score8;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1741699536988.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105339i352F22B310332A82/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1741699536988.png" alt="Tom_0-1741699536988.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Mar 2025 13:26:46 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-03-11T13:26:46Z</dc:date>
    <item>
      <title>How to score elements of an array specified in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-score-elements-of-an-array-specified-in-another-dataset/m-p/961495#M374837</link>
      <description>&lt;P&gt;I am sorry if this is a straight forward question but I cannot figure out how to solve this.&lt;/P&gt;&lt;P&gt;I have two datasets, one of values where each row is a set of values (and other columns but they are excluded for the sake of example) and one of sequences which I would like to sum for each observation. In the example data below I would like to have 4 new columns in the values data seq1_sum, seq2_sum, seq3_sum, and seq4_sum. These sums would be the sums over each of the sequences respectively. For example the seq4 column would be the sum across each row for score3, score4, and score7.&lt;/P&gt;&lt;P&gt;sequences:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Coreyw184_0-1741648086035.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105330iFCA403729235EA62/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Coreyw184_0-1741648086035.png" alt="Coreyw184_0-1741648086035.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;values:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Coreyw184_1-1741648167609.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105331i8DD781C18BA828ED/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Coreyw184_1-1741648167609.png" alt="Coreyw184_1-1741648167609.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2025 23:14:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-score-elements-of-an-array-specified-in-another-dataset/m-p/961495#M374837</guid>
      <dc:creator>Coreyw184</dc:creator>
      <dc:date>2025-03-10T23:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to score elements of an array specified in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-score-elements-of-an-array-specified-in-another-dataset/m-p/961499#M374839</link>
      <description>&lt;P&gt;Here is some fake data to more or less match what you have in your screenshots - run this and use PROC PRINT to look at these if you like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data seqs;
length seq $20 sequences $6 s1-s8 3;
array s {*} s1-s8;
do i=1 to dim(s);
	s[i]=(rand('uniform')&amp;lt;0.3);
end;
drop i;
call symputx("nseqs",_N_-1);
infile cards dsd truncover firstobs=1 dlm='|';
input seq sequences;
cards;
1,2,3,4,5,6,7,8|seq1
1,2,3,4|seq2
1,3,6,8|seq3
3,4,7|seq4
;
run;

data values;
length score1-score8 3;
array s {*} score1-score8;
do r=1 to 20;
	do i=1 to dim(s);
		s[i]=(rand('uniform')&amp;lt;0.6);
	end;
	output;
end;
drop r i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I can't say I really understand your request - especially whether you're trying to sum things vertically or horizontally.&amp;nbsp; My assumption based on what you said is that you want to sum horizontally... :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set
	seqs (in=A)
	values
	;
array T {&amp;amp;nseqs} $20 _temporary_;
array sc {*} score1-score8;
array sq {*} seq1-seq4;
if A then T[_N_]=seq;
else do;
	call missing(of sq[*]);
	do i=1 to dim(sq);
		do s=1 to countW(T[i],',');
			sq[i]+sc[scan(T[i],s,',')*1];
		end;
	end;
	output;
end;
keep score1-score8 seq1-seq4;
run;

proc print data=want; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Mar 2025 01:01:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-score-elements-of-an-array-specified-in-another-dataset/m-p/961499#M374839</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-03-11T01:01:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to score elements of an array specified in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-score-elements-of-an-array-specified-in-another-dataset/m-p/961502#M374841</link>
      <description>&lt;P&gt;Next time, you 'd better post your data by using a data step code,not just a picuture. Nobody would like to type it for you . This time I used quickbluefish 's code to generate your sample data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data seqs;
length seq $20 sequences $6 s1-s8 3;
array s {*} s1-s8;
do i=1 to dim(s);
	s[i]=(rand('uniform')&amp;lt;0.3);
end;
drop i;
call symputx("nseqs",_N_-1);
infile cards dsd truncover firstobs=1 dlm='|';
input seq sequences;
cards;
1,2,3,4,5,6,7,8|seq1
1,2,3,4|seq2
1,3,6,8|seq3
3,4,7|seq4
;
run;

data values;
length score1-score8 3;
array s {*} score1-score8;
do r=1 to 20;
	do i=1 to dim(s);
		s[i]=(rand('uniform')&amp;lt;0.6);
	end;
	output;
end;
drop r i;
run;

filename x temp;
data _null_;
 set seqs;
 file x;
 x=cats(sequences,'_sum=sum(',prxchange('s/(\d+)/score\1/',-1,seq),');');
 put x;
run;
data want;
 set values;
 %include x/source;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Mar 2025 01:19:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-score-elements-of-an-array-specified-in-another-dataset/m-p/961502#M374841</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-03-11T01:19:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to score elements of an array specified in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-score-elements-of-an-array-specified-in-another-dataset/m-p/961504#M374842</link>
      <description>&lt;P&gt;What you apparently want is code that looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The primary tool used here is the trailing&amp;nbsp;@ used in the PUT statements, which holds the output column pointer in place, waiting for the next PUT statement.&amp;nbsp; The last PUT has the pointer control '+ (-1)' which moves the pointer back one character, in order to replace the troublesome &lt;STRIKE&gt;unnecessary&lt;/STRIKE&gt; comma appended to the last variable name with a closing paren and a semi-colon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This program is untested in the absence of sample data in the form of working DATA steps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I see other responders have utilized the character variable SEQ, instead of the S1 through S8 variables that I used.&amp;nbsp; If those variables are not available, then change the DATA _NULL_ step to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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&amp;lt;countw(seq) then addend=cats(addend,',');
    put addend @;
  end;
  put ');';
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Mar 2025 01:57:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-score-elements-of-an-array-specified-in-another-dataset/m-p/961504#M374842</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2025-03-11T01:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to score elements of an array specified in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-score-elements-of-an-array-specified-in-another-dataset/m-p/961508#M374844</link>
      <description>&lt;P&gt;Use PROC SCORE.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/statug/latest/statug_score_syntax01.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/statug/latest/statug_score_syntax01.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might have to restructure your "scoring" dataset to get it to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want help provide actual datasets. And the answer you are looking for.&lt;/P&gt;
&lt;P&gt;You will probably want to reduce the problem to just a few variables and a few observations of data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Mar 2025 03:22:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-score-elements-of-an-array-specified-in-another-dataset/m-p/961508#M374844</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-03-11T03:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to score elements of an array specified in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-score-elements-of-an-array-specified-in-another-dataset/m-p/961509#M374845</link>
      <description>&lt;P&gt;I was motivated by Tom's PROC SCORE.&lt;/P&gt;
&lt;P&gt;You could use IML code to get the desired output which is most simple and efficient.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data seqs;
length seq $20 sequences $6 s1-s8 3;
array s {*} s1-s8;
do i=1 to dim(s);
	s[i]=(rand('uniform')&amp;lt;0.3);
end;
drop i;
call symputx("nseqs",_N_-1);
infile cards dsd truncover firstobs=1 dlm='|';
input seq sequences;
cards;
1,2,3,4,5,6,7,8|seq1
1,2,3,4|seq2
1,3,6,8|seq3
3,4,7|seq4
;
run;

data values;
length score1-score8 3;
array s {*} score1-score8;
do r=1 to 20;
	do i=1 to dim(s);
		s[i]=(rand('uniform')&amp;lt;0.6);
	end;
	output;
end;
drop r i;
run;




proc iml;
use seqs(keep=s:);
read all var _num_ into s;
close;
use values(keep=score:);
read all var _num_ into score;
close;
want=score*t(s);
create want from want[c=('sum_seq1':'sum_seq'+char(nrow(s)))];
append from want;
close;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Mar 2025 03:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-score-elements-of-an-array-specified-in-another-dataset/m-p/961509#M374845</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-03-11T03:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to score elements of an array specified in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-score-elements-of-an-array-specified-in-another-dataset/m-p/961543#M374856</link>
      <description>&lt;P&gt;Make sure your scoring dataset has _NAME_ and _TYPE_ variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data seq ;
  _type_='SCORE';
  input description:$20. _name_ $ score1-score8;
cards;
1,2,3,4,5,6,7,8 seq1 1 1 1 1 1 1 1 1
1,2,3,4         seq2 1 1 1 1 0 0 0 0
1,3,6,8         seq3 1 0 1 0 0 1 0 1
3,4,7           seq4 0 0 1 1 0 0 1 0
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now let's make up a few observations of data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data values;
  input id score1-score8;
cards;
1 1 2 3 4 5 6 7 8
2 0 1 0 1 0 1 0 1
3 1 1 1 1 1 1 1 1
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then score it&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc score data=values score=seq out=want;
  var score1-score8;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1741699536988.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105339i352F22B310332A82/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1741699536988.png" alt="Tom_0-1741699536988.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Mar 2025 13:26:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-score-elements-of-an-array-specified-in-another-dataset/m-p/961543#M374856</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-03-11T13:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to score elements of an array specified in another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-score-elements-of-an-array-specified-in-another-dataset/m-p/961606#M374872</link>
      <description>PROC SCORE was exactly what I needed, thank you!</description>
      <pubDate>Tue, 11 Mar 2025 21:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-score-elements-of-an-array-specified-in-another-dataset/m-p/961606#M374872</guid>
      <dc:creator>Coreyw184</dc:creator>
      <dc:date>2025-03-11T21:15:47Z</dc:date>
    </item>
  </channel>
</rss>

