<?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 do I figure out the best way to pair up between students? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-figure-out-the-best-way-to-pair-up-between-students/m-p/478884#M285939</link>
    <description>&lt;P&gt;Thanks so much everyone on the input. Especially to PG and Novinosrin, you took the time to write the code, in SQL and PROC. Now I have some solid examples to follow to solve similar problems in the future. So appreciative on this!!&lt;/P&gt;&lt;P&gt;&lt;img id="smileyvery-happy" class="emoticon emoticon-smileyvery-happy" src="https://communities.sas.com/i/smilies/16x16_smiley-very-happy.png" alt="Smiley Very Happy" title="Smiley Very Happy" /&gt;&lt;img id="smileyvery-happy" class="emoticon emoticon-smileyvery-happy" src="https://communities.sas.com/i/smilies/16x16_smiley-very-happy.png" alt="Smiley Very Happy" title="Smiley Very Happy" /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Jul 2018 01:48:23 GMT</pubDate>
    <dc:creator>XabiAlonso</dc:creator>
    <dc:date>2018-07-18T01:48:23Z</dc:date>
    <item>
      <title>How do I figure out the best way to pair up between students?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-figure-out-the-best-way-to-pair-up-between-students/m-p/474689#M285932</link>
      <description>&lt;P&gt;Hi SAS Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Need some help! I'm trying to start with&amp;nbsp;a given "student list", to create a "synergy list" that looks like below.&amp;nbsp;I've tried&amp;nbsp;many different ways, still no success yet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;/* Student List */&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;data student;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;infile datalines dlm=',';&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;input STUDENT_ID $3 SUBJECT1-SUBJECT5;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;datalines;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;001,1,0,0,1,1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;002,0,0,1,1,1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;003,0,1,1,0,1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;004,1,1,0,1,0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;/* Synergy List */&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;data synergy;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;infile datalines dlm=',';&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;input STUDENT_ID $3 STUDENT1-STUDENT4;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;datalines;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;001,3,2,1,2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;002,2,3,2,1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;003,1,2,3,1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;004,2,1,1,3&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The idea is this. With a list of students and the subjects they are interested in (value "1" equals interested), I would like to find out for each student which of their friends have the best synergy with them, ie. someone who share the most subjects they both like.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The plan is for each common interested subject between two students, I will assign a "synergy score" of 1. Eg. if student 001 and 002 both like Biology and English, they would be assigned a synergy score of "2" between them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In another words, I would like to figure a way to get a "synergy list" from a "student list". The synergy list is a N*N table with the synergy score between each student pair combination. N is total number of students.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, from the Synergy list above, I can tell Student 001 has the highest synergy score with 002 and 003 (both has synergy score of "2" with 001), which is potentially good for pair up.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any tips or help is appreciated!!&lt;/P&gt;</description>
      <pubDate>Sat, 30 Jun 2018 19:25:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-figure-out-the-best-way-to-pair-up-between-students/m-p/474689#M285932</guid>
      <dc:creator>XabiAlonso</dc:creator>
      <dc:date>2018-06-30T19:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do I figure out the best way to pair up between students?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-figure-out-the-best-way-to-pair-up-between-students/m-p/474695#M285933</link>
      <description>&lt;P&gt;The "natural" data format in SAS is the long form. Move your data from wide to long, do the tally, then move back to wide form:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Student List */
data student;
infile datalines dlm=',';
input STUDENT_ID $3 SUBJECT1-SUBJECT5;
array s subject: ;
do subj = 1 to dim(s);
    interest = s{subj};
    output;
    end;
drop subject: ;
datalines;
001,1,0,0,1,1
002,0,0,1,1,1
003,0,1,1,0,1
004,1,1,0,1,0
;

proc sql;
create table syn as
select
    a.student_id as student_id,    
    b.student_id as stud2,
    sum(a.interest and b.interest) as common_interest
from
    student as a inner join
    student as b on a.subj=b.subj
group by a.student_id, b.student_Id;
quit;

proc transpose data=syn out=synergy(drop=_name_) prefix=student;
by student_id;
id stud2;
var common_interest;
run;

proc print data=synergy; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 30 Jun 2018 20:38:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-figure-out-the-best-way-to-pair-up-between-students/m-p/474695#M285933</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-06-30T20:38:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I figure out the best way to pair up between students?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-figure-out-the-best-way-to-pair-up-between-students/m-p/474696#M285934</link>
      <description>&lt;P&gt;sounds like matching used in observational studies may be analogous: &lt;A href="http://www2.sas.com/proceedings/sugi29/173-29.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi29/173-29.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 30 Jun 2018 20:42:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-figure-out-the-best-way-to-pair-up-between-students/m-p/474696#M285934</guid>
      <dc:creator>pau13rown</dc:creator>
      <dc:date>2018-06-30T20:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do I figure out the best way to pair up between students?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-figure-out-the-best-way-to-pair-up-between-students/m-p/474704#M285935</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data student;
infile datalines dlm=',';
input STUDENT_ID $ SUBJECT1-SUBJECT5;
datalines;
001,1,0,0,1,1
002,0,0,1,1,1
003,0,1,1,0,1
004,1,1,0,1,0
;

data w;
set student;
_Student_id=student_id;
do n=1 to nobs;
grp+1;
set student point=_n_;
output;
set student nobs=nobs point=n;
output;
end;
run;

data w1;
set w;
by grp;
array t(*) subject:;
do i=1 to dim(t);
if sum(t(i), lag(t(i)))=2 then count+1;
end;
if not last.grp then count=0;
if count ne 0;
keep _student_id grp count;
run;

proc transpose data=w1 out=want(drop=_name_)  prefix=Student_;
by _Student_id;
var count;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 30 Jun 2018 22:24:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-figure-out-the-best-way-to-pair-up-between-students/m-p/474704#M285935</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-30T22:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do I figure out the best way to pair up between students?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-figure-out-the-best-way-to-pair-up-between-students/m-p/474713#M285936</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183379"&gt;@pau13rown&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;sounds like matching used in observational studies may be analogous: &lt;A href="http://www2.sas.com/proceedings/sugi29/173-29.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi29/173-29.pdf&lt;/A&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;Echoing&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183379"&gt;@pau13rown&lt;/a&gt;&amp;nbsp;it sounds like case control matching and if you’re using the latest version of SAS STAT there’s a PROC PSMATCH that can help with that.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 30 Jun 2018 23:37:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-figure-out-the-best-way-to-pair-up-between-students/m-p/474713#M285936</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-30T23:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I figure out the best way to pair up between students?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-figure-out-the-best-way-to-pair-up-between-students/m-p/474718#M285937</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/218599"&gt;@XabiAlonso&lt;/a&gt;&amp;nbsp;Your first post(Welcome bienvenido) to the SAS forum and that too with an interesting question. I'd go with PG's answer&amp;nbsp; for real and have fun with mine. If you are experienced user, I'm sure you'd comprehend both the solutions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can of course eliminate data w1 step and merge that into one with the previous and make in work in 2 steps. Have a great weekend&lt;/P&gt;</description>
      <pubDate>Sun, 01 Jul 2018 02:08:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-figure-out-the-best-way-to-pair-up-between-students/m-p/474718#M285937</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-01T02:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I figure out the best way to pair up between students?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-figure-out-the-best-way-to-pair-up-between-students/m-p/474723#M285938</link>
      <description>&lt;P&gt;Here is another version of my code which&amp;nbsp;is more appropriate if your data is already in a wide format dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Student List */
data student;
infile datalines dlm=',';
input STUDENT_ID $3 SUBJECT1-SUBJECT5;
datalines;
001,1,0,0,1,1
002,0,0,1,1,1
003,0,1,1,0,1
004,1,1,0,1,0
;

/* Convert wide to long format */
proc transpose data=student out=studLong prefix=interest name=subj;
by student_id;
var subject: ;
run;

/* Count common interests */
proc sql;
create table syn as
select
    a.student_id as student_id,    
    b.student_id as stud2,
    sum(a.interest1 and b.interest1) as common_interest
from
    studlong as a inner join
    studlong as b on a.subj=b.subj
group by a.student_id, b.student_Id;
quit;

/* Convert long to wide format */
proc transpose data=syn out=synergy(drop=_name_) prefix=student;
by student_id;
id stud2;
var common_interest;
run;

proc print data=synergy; run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 01 Jul 2018 02:41:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-figure-out-the-best-way-to-pair-up-between-students/m-p/474723#M285938</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-07-01T02:41:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I figure out the best way to pair up between students?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-figure-out-the-best-way-to-pair-up-between-students/m-p/478884#M285939</link>
      <description>&lt;P&gt;Thanks so much everyone on the input. Especially to PG and Novinosrin, you took the time to write the code, in SQL and PROC. Now I have some solid examples to follow to solve similar problems in the future. So appreciative on this!!&lt;/P&gt;&lt;P&gt;&lt;img id="smileyvery-happy" class="emoticon emoticon-smileyvery-happy" src="https://communities.sas.com/i/smilies/16x16_smiley-very-happy.png" alt="Smiley Very Happy" title="Smiley Very Happy" /&gt;&lt;img id="smileyvery-happy" class="emoticon emoticon-smileyvery-happy" src="https://communities.sas.com/i/smilies/16x16_smiley-very-happy.png" alt="Smiley Very Happy" title="Smiley Very Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 01:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-figure-out-the-best-way-to-pair-up-between-students/m-p/478884#M285939</guid>
      <dc:creator>XabiAlonso</dc:creator>
      <dc:date>2018-07-18T01:48:23Z</dc:date>
    </item>
  </channel>
</rss>

