Utilisez l'objet Hash lorsque vous devez joindre une table géante à une table de référence de taille petite ou moyenne (jusqu'à quelques gigaoctets selon votre RAM). C'est la solution idéale pour enrichir des flux de données transactionnels avec des référentiels (noms de clients, libellés produits) sans alourdir vos chaînes de traitement par des étapes de tri systématiques.
Type : CREATION_INTERNE
Les exemples utilisent des données générées (datalines) ou SASHELP.
| 1 | /* Création du jeu de données product_list */ |
| 2 | DATA work.product_list; |
| 3 | INFILE DATALINES dlm=','; |
| 4 | LENGTH Product_Id $12 Product_Name $50 Supplier_ID 8; |
| 5 | INPUT Product_Id $ Product_Name $ Supplier_ID; |
| 6 | DATALINES; |
| 7 | 240200100101,Grandslam Staff Tour Mhl Golf Gloves,3808 |
| 8 | 210200100017,Sweatshirt Children's O-Neck,3298 |
| 9 | 240400200022,Aftm 95 Vf Long Bg-65 White,1280 |
| 10 | 230100100017,Men's Jacket Rem,50 |
| 11 | 210200300006,Fleece Cuff Pant Kid'S,1303 |
| 12 | 210200500002,Children's Mitten,772 |
| 13 | 210200700016,Strap Pants BBO,798 |
| 14 | 210201000050,Kid Children's T-Shirt,2963 |
| 15 | 210200100009,Kids Sweat Round Neck,Large Logo,3298 |
| 16 | 210201000067,Logo Coord.Children's Sweatshirt,2963 |
| 17 | 220100100019,Fit Racing Cap,1303 |
| 18 | 220100100025,Knit Hat,1303 |
| 19 | 220100300001,Fleece Jacket Compass,772 |
| 20 | 220200200036,Soft Astro Men's Running Shoes,1747 |
| 21 | 230100100015,Men's Jacket Caians,50 |
| 22 | 230100500004,Backpack Flag, 6,5x9 Cm.,316 |
| 23 | 210200500006,Rain Suit, Plain w/backpack Jacket,772 |
| 24 | 230100500006,Collapsible Water Can,316 |
| 25 | 224040020000,Bat 5-Ply,3808 |
| 26 | 220200200035,Soft Alta Plus Women's Indoor Shoes,1747 |
| 27 | 240400200066,Memhis 350,Yellow Medium, 6-pack,1280 |
| 28 | 240200100081,Extreme Distance 90 3-pack,3808 |
| 29 | ; |
| 30 | run; |
| 31 | |
| 32 | /* Création du jeu de données supplier */ |
| 33 | data work.supplier; |
| 34 | infile datalines dlm=','; |
| 35 | length Supplier_ID 8 Supplier_Name $40 Supplier_Address $45 Country $2; |
| 36 | input Supplier_ID Supplier_Name $ Supplier_Address $ Country $; |
| 37 | datalines; |
| 38 | 50,Scandinavian Clothing A/S,Kr. Augusts Gate 13,NO |
| 39 | 316,Prime Sports Ltd,9 Carlisle Place,GB |
| 40 | 755,Top Sports,Jernbanegade 45,DK |
| 41 | 772,AllSeasons Outdoor Clothing,553 Cliffview Dr,US |
| 42 | 798,Sportico,C. Barquillo 1,ES |
| 43 | 1280,British Sports Ltd,85 Station Street,GB |
| 44 | 1303,Eclipse Inc,1218 Carriole Ct,US |
| 45 | 1684,Magnifico Sports,Rua Costa Pinto 2,PT |
| 46 | 1747,Pro Sportswear Inc,2434 Edgebrook Dr,US |
| 47 | 3298,A Team Sports,2687 Julie Ann Ct,US |
| 48 | 3808,Carolina Sports,3860 Grand Ave,US |
| 49 | ; |
| 50 | run; |
| 51 | |
| 52 | data supplier_info; |
| 53 | drop rc; |
| 54 | length Supplier_Name $40 Supplier_Address $ 45 Country $ 2; |
| 55 | if _N_=1 then do; |
| 56 | declare hash S(dataset:'work.supplier'); |
| 57 | S.definekey('Supplier_ID'); |
| 58 | S.definedata('Supplier_Name', |
| 59 | 'Supplier_Address','Country'); |
| 60 | S.definedone(); |
| 61 | call missing(Supplier_Name, |
| 62 | Supplier_Address,Country); |
| 63 | end; |
| 64 | set work.product_list; |
| 65 | rc=S.find(); |
| 66 | run; |
| 67 | |
| 68 | proc print data=supplier_info; |
| 69 | var Product_ID Supplier_ID Supplier_Name |
| 70 | Supplier_Address Country; |
| 71 | title "Product Information"; |
| 72 | RUN; |
| 73 | title; |