Hi @Marc_y Great precise answer by @Ksharp and a nice detailed thought out by @ed_sas_member . To my mind, a way to understand the problem as we break into pieces with your initial thought of arrays would perhaps be to devise an algorithm in steps like
1. Look at pairs
2. Check for even outcome
3. Roll up
4. Transpose to wide to meet the stated requirement
i.e in SAS syntax, the possibility is
data have;
input basket g1 g2 g3 g4;
datalines;
1 1 0 1 0
2 0 0 1 1
3 1 1 1 0
4 1 1 0 1
5 0 1 1 0
6 0 0 0 1
;
run;
/*Get/compare pairs*/
data temp;
set have;
array t g1-g4;
length item $5;
do g=1 to dim(t);
do j=1 to dim(t);
item=cats('g',g);
p1=t(g);
p2=t(j);
if sum(p1,p2)=2 then output;
end;
end;
keep item j p:;
run;
/*Roll up eligible pairs*/
proc sql;
create table temp1 as
select item,j,sum(p1) as s
from temp
group by item,j;
quit;
/*To get the wide structure*/
proc transpose data=temp1 out=want(drop=_:) prefix=g;
by item;
var s;
id j;
run;
Of course the above may require a slight adjustments to get the appropriate variable names in place as is in your original dataset. The idea is to validate the thought process/approach 🙂
For someone who mentions " but my knowledge in SAS is too limited to work out how exactly this is done", I really do appreciate your thought process is very noteworthy
... View more