Download presentation
Presentation is loading. Please wait.
1
Self-joins Using PROC SQL
Chapter 3 Supplement Self-joins Using PROC SQL
2
Self-Joins Self-joins, or Reflexive Joins are used to compare values within a data set Examples typically use equality operations to create a join Interesting short-cut to create choose(n,2) pairs
3
2011 SEC Football Scores Date Winning Team Winning Score Losing Team
Losing Score 11/19/2011 Alabama 45 Georgia Southern 21 Arkansas 44 Mississippi State 17 LSU 52 Ole Miss 3 Tennessee 27 Vanderbilt 11/12/2011 South Carolina Florida 12
4
Self-Joins Note that USC’s winning score on November 12 matches Mississippi State’s losing score on November 19 We can record all such instances using a reflexive join The reflexive join can look like an outer union
5
Self-Join Syntax proc sql; select winner.wscore, winner.date, winner.wteam, loser.date, loser.lteam from secscores as winner, secscores as loser where winner.wscore=loser.lscore; quit; Most examples make sure a record doesn’t join with itself, but that can’t happen here (no ties in football).
6
Self-Join Syntax We do not have to use equality operators: proc sql;
select winner.wscore, winner.date, winner.wteam, loser.date, loser.lteam from secscores as winner, secscores as loser where winner.wscore lt loser.lscore; quit; I have another example just for fun. End of Day 9 (50 minutes).
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.