<?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: Using multiple tables to match and group data in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-multiple-tables-to-match-and-group-data/m-p/300372#M20435</link>
    <description>&lt;P&gt;Thanks for the feedback. &amp;nbsp;I added a few more lines for each table and also an example of what I would like to end up with.&lt;/P&gt;</description>
    <pubDate>Fri, 23 Sep 2016 13:43:34 GMT</pubDate>
    <dc:creator>LizGagne</dc:creator>
    <dc:date>2016-09-23T13:43:34Z</dc:date>
    <item>
      <title>Using multiple tables to match and group data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-multiple-tables-to-match-and-group-data/m-p/300146#M20425</link>
      <description>&lt;P&gt;I have 3 tables, all with bits of into that I need to come together into one dataset. The variable "employeeID" links to a variable called "calcID", the calcID variable then links to a variable called "student_ID". Basically what this does reveals which students were included in a teachers evaluation measures (so teachers can have multiple calc id's, based on the grade_subject_id variable, but only one employee id).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I get SAS to look at each calcID from multiple tables to find a match (not necessarily on the same row) and then if there is a match, the coordinating employeeID and grade_subject_ID should be input for each student_ID?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this isn't possible in SAS, is there a way to make this happen using SQL (either PROC SQL or SQL Server)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC IMPORT DATAFILE= "C:\Users\egagne\Desktop\Spillover\Y16_GROW_Teacher BN, Employeeid, GRADE_SUBJECT_ID, linkB, subgroup_id, MGP, student_n, calcID, MGP, avg_prescore, target_population, HEDI, HEDI_points.csv"&lt;BR /&gt;OUT = Y16_GROW_Teacher replace; GETNAMES=Yes;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;PROC IMPORT DATAFILE="C:\Users\egagne\Desktop\Spillover\Y16_CALC_Student student id sgp calcid.csv"&lt;BR /&gt;out=Y16_CALC_Stud dbms=csv replace; GETNAMES=Yes;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;DATA Y16_CALC_Stud (RENAME=(StudCalcID = calcID));&lt;BR /&gt;SET Y16_CALC_Stud;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;PROC IMPORT DATAFILE="C:\Users\egagne\Desktop\Spillover\Y16_LINK_GM school_DBN empID grade_subject_id STUDENT_ID score.csv" &lt;BR /&gt;DBMS=csv OUT= Y16_LINK_GM replace; GETNAMES=NO;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;OPTIONS VALIDVARNAME=ANY OPTIONS SPOOL;&lt;BR /&gt;DATA Y16_LINK_GM (RENAME=(VAR1=school_DBN VAR2=employeeID VAR3=grade_subject_ID VAR4=student_ID VAR5=score)); &lt;BR /&gt;SET Y16_LINK_GM;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;PROC SORT data=Y16_LINK_GM OUT=Y16_LINK_GM_SORT; BY DESCENDING employeeID student_ID;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;PROC SORT DATA=Y16_GROW_Teacher OUT=Y16_GROW_Teacher_SORT;&lt;BR /&gt;BY DESCENDING employeeID calcID;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;PROC SORT DATA=Y16_CALC_Stud OUT=Y16_CALC_Student_SORT;&lt;BR /&gt;BY DESCENDING calcID;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;DATA Y16_GROW_LINK_MERGE;&lt;BR /&gt;MERGE Y16_LINK_GM (in=x) Y16_GROW_TEACHER_SORT(in=y);&lt;BR /&gt;BY DESCENDING employeeID calcID;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;PROC SORT DATA=Y16_GROW_LINK_MERGE OUT=Y16_GROW_LINK_MERGE_SORT;&lt;BR /&gt;BY DESCENDING calcID;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;DATA Y16_CALC_GROW_LINK_MERGE;&lt;BR /&gt;MERGE Y16_CALC_Student_SORT (in=x) Y16_GROW_LINK_MERGE_SORT(in=y);&lt;BR /&gt;by descending calcID;&lt;BR /&gt;if x and y;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;PROC SORT DATA= Y16_CALC_GROW_LINK_MERGE OUT=SpilloverFinal;&lt;BR /&gt;BY DESCENDING student_ID;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what the tables look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Y16_LINK_GM&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;SPAN class="lit"&gt;DBN     employee_ID gradeu_subject_ID  student_ID   Score&lt;BR /&gt;00&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;M123  &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;987654&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;      ES_SCI4            &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;123456789&lt;/SPAN&gt;    &lt;SPAN class="lit"&gt;45&lt;/SPAN&gt;
&lt;SPAN class="lit"&gt;00&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;M123  &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;654987&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;      ES_MAT2            &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;987456789&lt;/SPAN&gt;    &lt;SPAN class="lit"&gt;68&lt;/SPAN&gt; 
&lt;SPAN class="lit"&gt;00X&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;123  &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;123456&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;      ES_SCI4            567845895    87&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Y16_GROW_Teacher&lt;/P&gt;&lt;PRE class="lang-sql prettyprint prettyprinted"&gt;&lt;CODE&gt;&lt;SPAN class="pln"&gt;BN  employeeID  GRADE_SUBJECT   linkB   subgroup_ID MGP          student_n  calcID      avg_prescore    target_population   HEDI    HEDI_points
X123 &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;123456     &lt;/SPAN&gt;&lt;SPAN class="pln"&gt;ES_SCI4          &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;0&lt;/SPAN&gt;       &lt;SPAN class="lit"&gt;0&lt;/SPAN&gt;          &lt;SPAN class="lit"&gt;10.7000456&lt;/SPAN&gt;    &lt;SPAN class="lit"&gt;24&lt;/SPAN&gt;        &lt;SPAN class="lit"&gt;1191298.7&lt;/SPAN&gt;   &lt;SPAN class="lit"&gt;-15.12398714&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;    Individual          H       &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;88&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;K123 &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;9852178&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;    ES_MAT6          &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;0&lt;/SPAN&gt;       &lt;SPAN class="lit"&gt;0&lt;/SPAN&gt;          &lt;SPAN class="lit"&gt;15.0569811&lt;/SPAN&gt;    &lt;SPAN class="lit"&gt;19&lt;/SPAN&gt;        &lt;SPAN class="lit"&gt;5698985.3&lt;/SPAN&gt;   &lt;SPAN class="lit"&gt;-23.74125892&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;    Individual          H       &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;72&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;M123 &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;9874562&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;    ES_MAT2          &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;0&lt;/SPAN&gt;       &lt;SPAN class="lit"&gt;0&lt;/SPAN&gt;          &lt;SPAN class="lit"&gt;56.0265487&lt;/SPAN&gt;    &lt;SPAN class="lit"&gt;16&lt;/SPAN&gt;        &lt;SPAN class="lit"&gt;8527412.3&lt;/SPAN&gt;   &lt;SPAN class="lit"&gt;-87.65478928&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;    Individual          H       &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;94&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Y16_CALC_Stud&lt;/P&gt;&lt;PRE class="lang-sql prettyprint prettyprinted"&gt;&lt;CODE&gt;&lt;SPAN class="pln"&gt;Student_ID  StudSGP StudCalcID&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;369123661&lt;/SPAN&gt;   &lt;SPAN class="lit"&gt;15&lt;/SPAN&gt;      &lt;SPAN class="lit"&gt;6659.2&lt;/SPAN&gt;
&lt;SPAN class="lit"&gt;985432125&lt;/SPAN&gt;   &lt;SPAN class="lit"&gt;54&lt;/SPAN&gt;      &lt;SPAN class="lit"&gt;8527412.3&lt;/SPAN&gt;
&lt;SPAN class="lit"&gt;567845895&lt;/SPAN&gt;   &lt;SPAN class="lit"&gt;-2      1191298.7&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;What I'd like to end up with (more or less):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;student_ID Score StudSGP grade_subject_ID employee_ID HEDI HEDI_points DBN     avg_prescore
567845895   25   -2      ES_SCI4          123456      H    94          00X123  -15.12398714&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2016 16:49:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-multiple-tables-to-match-and-group-data/m-p/300146#M20425</guid>
      <dc:creator>LizGagne</dc:creator>
      <dc:date>2016-09-23T16:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: Using multiple tables to match and group data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-multiple-tables-to-match-and-group-data/m-p/300277#M20434</link>
      <description>&lt;P&gt;A few more lines of example data, and the desired result , would help to better&amp;nbsp;describe your requirement.&lt;/P&gt;
&lt;P&gt;SQL is usually the better tool when linking multiple tabels with different keys.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2016 03:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-multiple-tables-to-match-and-group-data/m-p/300277#M20434</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-09-23T03:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using multiple tables to match and group data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-multiple-tables-to-match-and-group-data/m-p/300372#M20435</link>
      <description>&lt;P&gt;Thanks for the feedback. &amp;nbsp;I added a few more lines for each table and also an example of what I would like to end up with.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2016 13:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-multiple-tables-to-match-and-group-data/m-p/300372#M20435</guid>
      <dc:creator>LizGagne</dc:creator>
      <dc:date>2016-09-23T13:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using multiple tables to match and group data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-multiple-tables-to-match-and-group-data/m-p/300423#M20436</link>
      <description>&lt;P&gt;Example data does not have LINK_GM information for student &lt;SPAN class="token number"&gt;567845895 and none of the employee_id values appear in both data sets. So it may be a tad difficult to test code against.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token number"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2016 15:57:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-multiple-tables-to-match-and-group-data/m-p/300423#M20436</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-09-23T15:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using multiple tables to match and group data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-multiple-tables-to-match-and-group-data/m-p/300439#M20438</link>
      <description>&lt;P&gt;Fixed.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2016 16:49:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-multiple-tables-to-match-and-group-data/m-p/300439#M20438</guid>
      <dc:creator>LizGagne</dc:creator>
      <dc:date>2016-09-23T16:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using multiple tables to match and group data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-multiple-tables-to-match-and-group-data/m-p/300492#M20446</link>
      <description>&lt;P&gt;I think the following code does what you are requesting. I had to make my own data sets so if you have any place where a variable that appears numeric but is character in one set and numeric in the other you may have to do your own conversion.&lt;/P&gt;
&lt;P&gt;I don't use EG very much so I have no idea if the point and click will match things this way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.Y16_LINK_GM;
   informat dbn $6. employee_ID grade_subject_ID student_ID $10.;
   input DBN     employee_ID grade_subject_ID  student_ID   Score;
datalines;
00M123  987654      ES_SCI4            123456789    45
00M123  654987      ES_MAT2            987456789    68 
00X123  123456      ES_SCI4            567845895    87
;
run;

data work.Y16_GROW_Teacher;
   informat  bn $6.   employeeID GRADE_SUBJECT $10.   linkB   subgroup_ID MGP          student_n  calcID      avg_prescore best16.      target_population $10. HEDI $1.  ;
   input BN  employeeID  GRADE_SUBJECT   linkB   subgroup_ID MGP          student_n  calcID      avg_prescore    target_population   HEDI    HEDI_points;
datalines;
X123 123456     ES_SCI4          0       0          10.7000456    24        1191298.7   -15.12398714    Individual          H       88
K123 9852178    ES_MAT6          0       0          15.0569811    19        5698985.3   -23.74125892    Individual          H       72
M123 9874562    ES_MAT2          0       0          56.0265487    16        8527412.3   -87.65478928    Individual          H       94
;
run;

data work.Y16_CALC_Stud;
   informat Student_ID $10.;
   input Student_ID  StudSGP StudCalcID;
datalines;
369123661   15      6659.2
985432125   54      8527412.3
567845895   -2      1191298.7
;
run;


proc sql;
   create table work.temp as 
   select c.Student_ID,c.score,c.StudSGP,c.grade_subject_ID,c.employee_ID,d.HEDI,d.HEDI_points,d.avg_prescore
   from (
         select a.Student_ID,a.StudSGP, StudCalcID, b.DBN, b.Score ,b.employee_ID, b.grade_subject_ID
         from  work.Y16_CALC_Stud as a left join work.Y16_LINK_GM as b
            on a.Student_ID = b.Student_ID
        ) as c   left join  work.Y16_GROW_Teacher as d on
        c.StudCalcID = d.calcID and c.employee_ID=d.employeeID and c.grade_subject_ID=d.GRADE_SUBJECT 
   ;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Sep 2016 20:54:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-multiple-tables-to-match-and-group-data/m-p/300492#M20446</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-09-23T20:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: Using multiple tables to match and group data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-multiple-tables-to-match-and-group-data/m-p/300800#M20450</link>
      <description>&lt;P&gt;Thanks so much&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;. &amp;nbsp;I tried your code and am still getting a lot of errors. &amp;nbsp;Mostly&amp;nbsp;&lt;/P&gt;&lt;PRE class="lang-sql prettyprint prettyprinted"&gt;&lt;CODE&gt;&lt;SPAN class="pln"&gt;ERROR&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; Unresolved reference &lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;to&lt;/SPAN&gt; &lt;SPAN class="kwd"&gt;table&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;/&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;correlation name&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried using the full table names instead of a., b., and so on but that doesn't make a difference. &amp;nbsp;Any ideas?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 16:16:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-multiple-tables-to-match-and-group-data/m-p/300800#M20450</guid>
      <dc:creator>LizGagne</dc:creator>
      <dc:date>2016-09-26T16:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: Using multiple tables to match and group data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-multiple-tables-to-match-and-group-data/m-p/300806#M20451</link>
      <description>&lt;P&gt;Post the log of the exact code run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that with the nested select you really may want to use at least one set of aliases as that nest is not the same as the original data.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 16:24:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Using-multiple-tables-to-match-and-group-data/m-p/300806#M20451</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-09-26T16:24:54Z</dc:date>
    </item>
  </channel>
</rss>

