/* The SET statement */ data one ; length toy1 $ 12 toy2 $ 12 ; input name $ age toy1 $ toy2 $ ; cards ; John 11 DVD's Football George 9 GIJoe Scrabble ; data two ; length toy1 $ 12 toy2 $ 12 ; input name $ age toy1 $ toy2 $ ; cards ; Jenny 11 Soccer Horseriding Suzie 9 Barbie NewDress ; data both ; set one two ; proc print ; title 'Toy Wish Lists' ; run ; /* A 1-1 MERGE, usually not a good way to merge */ data three ; input name $ age ; title ' ' ; cards ; John 11 George 9 Jenny 11 Suzie 9 ; data four ; length toy1 $ 12 toy2 $ 12 ; input toy1 $ toy2 $ ; cards ; DVD's Football GIJoe Scrabble Soccer Horseriding Barbie NewDress ; data both11a ; merge three four ; proc print ; title 'A successful 1-1 merge' ; run ; data five ; input name $ age ; title ' ' ; cards ; John 11 George 9 Sam 14 Jim 12 Jenny 11 Suzie 9 ; data both11b ; merge five four ; proc print ; title 'An unsuccessful 1-1 merge' ; run ; /* MERGE with a BY statement, much more stable */ data six ; length toy1 $ 12 toy2 $ 12 ; input name $ toy1 $ toy2 $ ; cards ; John DVD's Football George GIJoe Scrabble Jenny Soccer Horseriding Suzie Barbie NewDress ; proc sort data = five ; by name ; proc sort data = six ; by name ; data bothby ; merge five six ; by name ; run ; proc print ; title 'A successful MERGE using BY' ; run ;