Load a SAS data set into a Hash Object using PROC FCMP. The loading of the SAS data set into a Hash Object using PROC FCMP occurs only one time and not each time the function is called in the DATA step. Call the user defined function created in PROC FCMP inside the DATA step to look up values in a table. The ability to use the Component Objects (hash objects and hash iterators) are available to be used with PROC FCMP beginning in SAS 9.3 and beyond. For a complete list of attributes, methods and statements available to PROC FCMP, see the Component Objects and PROC FCMP documentation link below. Note: The DECLARE statement, ADD method, REMOVE method, and REPLACE method are missing from the list in the documentation.
For more information on Component Objects and PROC FCMP, click the SAS 9.3 documentation link for PROC FCMP below:
PROC FCMP and DATA Step Component Objects
Click on the link below to go to the SAS 9.3 documentation for DATA Step Component Objects:
SAS 9.3 Component Objects: Reference
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.
/* Master list of southern states and capitals */
data southernstcap_masterlist;
infile datalines dlm="," dsd truncover;
input state : $25. capital : $25.;
datalines;
North Carolina, Raleigh
Virginia, Richmond
South Carolina, Columbia
Arkansas, Little Rock
Mississippi, Jackson
Alabama, Montgomery
Louisiana, Baton Rouge
Tennessee, Nashville
Georgia, Atlanta
Florida, Tallahassee
Kentucky, Frankfort
West Virginia, Charleston
;
run;
/* List of states without a capital */
data states;
infile datalines truncover;
input state $char25.;
datalines;
Virginia
North Carolina
Texas
Alabama
Mississippi
Georgia
Arkansas
;
run;
/* Load a lookup table into a hash object using PROC FCMP. Use the FIND method to
determine if the key value has a match in the hash object. If so, output the value
or return a value of Not Found.
Note: For detailed information regarding object dot programming in the DATA step,
please refer to SAS 9.3 Component Objects: Reference. */
proc fcmp outlib=work.functions.samples;
function sas_lkupcapital(state $) $25;
declare hash hh (dataset: "work.southernstcap_masterlist");
rc=hh.definedata("capital");
rc=hh.definekey("state");
rc=hh.definedone();
rc=hh.find();
if rc eq 0 then return(capital);
else return('Not Found');
endsub;
quit;
options cmplib=work.functions;
/* Call the user-defined function created by Proc FCMP to return the value of the capital
for each state */
data test;
set states;
capital_returnval=sas_lkupcapital(state);
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.
Type: | Sample |
Topic: | SAS Reference ==> Component Objects ==> Component Objects SAS Reference ==> Procedures ==> FCMP |
Date Modified: | 2012-09-17 15:49:30 |
Date Created: | 2012-08-14 09:15:57 |
Product Family | Product | Host | Product Release | SAS Release | ||
Starting | Ending | Starting | Ending | |||
SAS System | Base SAS | 64-bit Enabled Solaris | 9.3 | 9.3 TS1M0 | ||
64-bit Enabled HP-UX | 9.3 | 9.3 TS1M0 | ||||
64-bit Enabled AIX | 9.3 | 9.3 TS1M0 | ||||
Windows Vista for x64 | 9.3 | 9.3 TS1M0 | ||||
Windows Vista | 9.3 | 9.3 TS1M0 | ||||
Windows 7 Ultimate x64 | 9.3 | 9.3 TS1M0 | ||||
Windows 7 Ultimate 32 bit | 9.3 | 9.3 TS1M0 | ||||
Windows 7 Professional x64 | 9.3 | 9.3 TS1M0 | ||||
Windows 7 Professional 32 bit | 9.3 | 9.3 TS1M0 | ||||
Windows 7 Home Premium x64 | 9.3 | 9.3 TS1M0 | ||||
Windows 7 Home Premium 32 bit | 9.3 | 9.3 TS1M0 | ||||
Windows 7 Enterprise x64 | 9.3 | 9.3 TS1M0 | ||||
Windows 7 Enterprise 32 bit | 9.3 | 9.3 TS1M0 | ||||
Microsoft Windows XP Professional | 9.3 | 9.3 TS1M0 | ||||
Microsoft Windows Server 2008 for x64 | 9.3 | 9.3 TS1M0 | ||||
Microsoft Windows Server 2008 | 9.3 | 9.3 TS1M0 | ||||
Microsoft Windows Server 2003 for x64 | 9.3 | 9.3 TS1M0 | ||||
Microsoft Windows Server 2003 Standard Edition | 9.3 | 9.3 TS1M0 | ||||
Microsoft Windows Server 2003 Enterprise Edition | 9.3 | 9.3 TS1M0 | ||||
Microsoft Windows Server 2003 Datacenter Edition | 9.3 | 9.3 TS1M0 | ||||
Microsoft® Windows® for x64 | 9.3 | 9.3 TS1M0 | ||||
Z64 | 9.3 | 9.3 TS1M0 | ||||
z/OS | 9.3 | 9.3 TS1M0 | ||||
HP-UX IPF | 9.3 | 9.3 TS1M0 | ||||
Linux | 9.3 | 9.3 TS1M0 | ||||
Linux for x64 | 9.3 | 9.3 TS1M0 | ||||
Solaris for x64 | 9.3 | 9.3 TS1M0 |