The examples use generated data (DATA step with DATALINES) to simulate the `product_list` and `supplier` tables.
1 Code Block
DATA STEP Data
Explanation : This DATA step code block creates the `work.product_list` dataset using in-line data (DATALINES). It defines the variables `Product_Id`, `Product_Name`, and `Supplier_ID` with their respective types and lengths. Spaces and special characters in `Product_Name` have been replaced by underscores for better handling via DATALINES.
Explanation : This DATA step code block creates the `work.supplier` dataset using in-line data (DATALINES). It defines the variables `Supplier_ID`, `Supplier_Name`, `Supplier_Address`, and `Country` with their respective types and lengths. Spaces and special characters have been replaced by underscores for better handling via DATALINES.
Copied!
DATA work.supplier;
LENGTH Supplier_ID 8 Supplier_Name $40 Supplier_Address $45 Country $2;
INPUT Supplier_ID Supplier_Name :$40. Supplier_Address :$45. Country $;
DATALINES;
50 Scandinavian_Clothing_A/S Kr._Augusts_Gate_13 NO
316 Prime_Sports_Ltd 9_Carlisle_Place GB
755 Top_Sports Jernbanegade_45 DK
772 AllSeasons_Outdoor_Clothing 553_Cliffview_Dr US
798 Sportico C._Barquillo_1 ES
1280 British_Sports_Ltd 85_Station_Street GB
1303 Eclipse_Inc 1218_Carriole_Ct US
1684 Magnifico_Sports Rua_Costa_Pinto_2 PT
1747 Pro_Sportswear_Inc 2434_Edgebrook_Dr US
3298 A_Team_Sports 2687_Julie_Ann_Ct US
3808 Carolina_Sports 3860_Grand_Ave US
;
RUN;
1
DATA work.supplier;
2
LENGTH Supplier_ID 8 Supplier_Name $40 Supplier_Address $45 Country $2;
3
INPUT Supplier_ID Supplier_Name :$40. Supplier_Address :$45. Country $;
4
DATALINES;
5
50 Scandinavian_Clothing_A/S Kr._Augusts_Gate_13 NO
6
316 Prime_Sports_Ltd 9_Carlisle_Place GB
7
755 Top_Sports Jernbanegade_45 DK
8
772 AllSeasons_Outdoor_Clothing 553_Cliffview_Dr US
9
798 Sportico C._Barquillo_1 ES
10
1280 British_Sports_Ltd 85_Station_Street GB
11
1303 Eclipse_Inc 1218_Carriole_Ct US
12
1684 Magnifico_Sports Rua_Costa_Pinto_2 PT
13
1747 Pro_Sportswear_Inc 2434_Edgebrook_Dr US
14
3298 A_Team_Sports 2687_Julie_Ann_Ct US
15
3808 Carolina_Sports 3860_Grand_Ave US
16
;
17
RUN;
3 Code Block
DATA STEP / PROC PRINT
Explanation : 1. Includes a LENGTH statement to ensure that the `Supplier_Name`, `Supplier_Address`, and `Country` variables are defined in the PDV (Program Data Vector).
2. During the first iteration of the DATA step, declares the hash object `S`. Assigns `Supplier_ID` as the key for the hash object. Includes the values of `Supplier_Name`, `Supplier_Address`, and `Country` from the `work.supplier` dataset.
3. Since `Supplier_Name`, `Supplier_Address`, and `Country` are not explicitly assigned initial values, SAS writes a NOTE to the log indicating that the variables are uninitialized. `CALL MISSING` suppresses this NOTE.
4. Reads an observation from the `product_list` dataset.
5. The `FIND` method is called to check if the `Supplier_ID` from `product_list` matches the `Supplier_ID` key of one of the hash object entries. If there is a match (`rc=0`), the observation is written to the `supplier_info` dataset.
PROC PRINT then displays the contents of the `supplier_info` dataset.
Copied!
data supplier_info;
drop rc;
length Supplier_Name $40 Supplier_Address $ 45 Country $ 2; /* 1*/
if _N_=1 then do;
declare hash S(dataset:'work.supplier'); /* 2*/
S.definekey('Supplier_ID');
S.definedata('Supplier_Name',
'Supplier_Address','Country');
S.definedone();
call missing(Supplier_Name,
Supplier_Address,Country); /* 3*/
end;
set work.product_list; /* 4*/
rc=S.find(); /* 5*/
run;
proc print data=supplier_info;
var Product_ID Supplier_ID Supplier_Name
Supplier_Address Country;
title "Product Information";
run;
title;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.