Sie sind auf Seite 1von 3

Sample 24704: Perform multiple lookups for each observation of a SAS data set

Load a lookup table into a hash object and execute multiple FIND methods for each observation of a data set. Note: For detailed information regarding object dot programming in the DATA step, please refer to SAS 9.1 Language Reference: Concepts, Using DATA Step Component Objects.

These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.

/* Create sample data */ data lookup; infile datalines truncover; input emp_nbr emp_nm $20.; datalines; 1000 John Ho 1001 Madhu Sundrie 1002 Jim Simpson 1003 Chris Hostess 2003 Rachel Holiday 2005 Mert Demitter 3004 Amit Gong ; data group; input emp_nbr1 mgr_id mandir_id Account $6. @23 contract_dt mmddyy10.; format contract_dt mmddyy10.; datalines; 1000 2003 3004 ABC Co 05/04/2002 1001 2005 3004 NBC 06/08/2001 1003 2003 3004 XYZ 01/02/2003 ;

data final(keep=employee manager mandir account contract_dt); length emp_nbr 8; length emp_nm $ 20; /* On the first iteration of the DATA step, define the hash object H. /* Use the DATASET: argument tag to load WORK.LOOKUP into H. The /* HASHEXP argument tag specifies the number of 'buckets' to use to /* store the data. The maximum value for HASHEXP is 20. You can use /* HASHEXP as a 'tuning knob' that can help with retrieval speed from /* the hash object. Benchmark to determine the best size if using /* HASHEXP. Define the variable (EMP_NBR) that will act as the KEY /* for the hash lookup and define the data variable (EMP_NM) to be /* associated with the KEY. Use CALL MISSING to avoid a note in the /* log indicating the KEY and DATA variables are uninitialized. if _N_ = 1 then do; declare hash h(dataset: "work.lookup", hashexp: 6); h.defineKey('emp_nbr'); h.defineData('emp_nm'); h.defineDone(); call missing(emp_nbr, emp_nm); end; set group; array name(*) $ 20 employee manager mandir; array id(*) emp_nbr1 mgr_id mandir_id; /* For every element in the array NAME, assign the 'correlated' value from /* the array ID into EMP_NBR. Use the FIND method to search for that /* value in the hash object H. If a match is located (RC=0), assign the /* data value from EMP_NM into the specified element in the array NAME. do i=1 to dim(name); emp_nbr=id(i); rc=h.find(); if (rc=0) then name(i)=emp_nm; end; run; proc print; run; */ */ */ */ */ */ */ */ */ */ */ */ */ */

These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.

contract_

Obs 1 2 3

Account ABC Co NBC XYZ

dt 05/04/2002 06/08/2001 01/02/2003

employee John Ho Madhu Sundrie Chris Hostess

manager Rachel Holiday Mert Demitter Rachel Holiday

mandir Amit Gong Amit Gong Amit Gong

Load a lookup table into a hash object and execute multiple FIND methods for each observation of a data set. Type: Sample Topic: SAS Reference ==> DATA Step SAS Reference ==> Component Objects Date Modified: 2006-05-25 03:02:51 Date Created: 2004-09-30 14:09:06

Operating System and Release Information Product Family Product SAS System Base SAS Host Tru64 UNIX OpenVMS Alpha HP-UX IPF Linux 64-bit Enabled Solaris 64-bit Enabled HP-UX 64-bit Enabled AIX Microsoft Windows for 64-Bit Itanium-based Systems z/OS Starting Release Ending Release 9.1 TS1M0 9.1 TS1M0 9.1 TS1M0 9.1 TS1M0 9.1 TS1M0 9.1 TS1M0 9.1 TS1M0 9.1 TS1M0 9.1 TS1M0 n/a n/a n/a n/a n/a n/a n/a n/a n/a

Contact Us | Sitemap | www.sas.com | Terms of Use & Legal Information | Privacy Statement Copyright 2008 SAS Institute Inc. All Rights Reserved.

Das könnte Ihnen auch gefallen