Sample 45243: Using PROC FCMP to create a user-defined function to convert from Inches to Centimeters and Centimeters to Inches
Using PROC FCMP to create a function, which converts from Inches to Centimeters, Centimeters to Inches or missing if values passed are invalid.
Additional Documentation
For more information on PROC FCMP click on the link below to go to a
2007 SAS Global Forum paper about the procedure.
User-Written DATA Step Functions
Click on the link below to go to the SAS 9.2 documentation about PROC FCMP
SAS 9.2 PROC FCMP Documentation
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.
/*Use an IF condition inside FCMP to control the logic
of returning the value of CONV */
proc fcmp outlib=work.functions.samples;
function sas_measure(amt,val1 $,val2 $);
if val1='inches' and val2='cm' then do;
conv=amt*2.54;
end;
else if val1='cm' and val2='inches' then do;
conv=amt*.393700787;
end;
else conv=0;
return(conv);
endsub;
quit;
options cmplib=work.functions;
/*Call the function created in FCMP */
data one;
input x y1 $ y2 $;
new=sas_measure(x,y1,y2);
cards;
10 inches cm
25.4 cm inches
25.4 lb inches
;
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.
Obs x y1 y2 new
1 10.0 inches cm 25.4000
2 25.4 cm inches 10.0000
3 25.4 lb inches 0.0000
Type: | Sample |
Topic: | SAS Reference ==> Procedures ==> FCMP
|
Date Modified: | 2012-01-06 13:37:08 |
Date Created: | 2011-12-29 21:37:02 |
Operating System and Release Information
SAS System | Base SAS | z/OS | 9.2 TS2M0 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS2M0 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS2M0 | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS2M0 | |
Microsoft Windows XP 64-bit Edition | 9.2 TS2M0 | |
Microsoft® Windows® for x64 | 9.2 TS2M0 | |
Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS2M0 | |
Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS2M0 | |
Microsoft Windows Server 2003 Standard Edition | 9.2 TS2M0 | |
Microsoft Windows Server 2003 for x64 | 9.2 TS2M0 | |
Microsoft Windows Server 2008 for x64 | 9.2 TS2M0 | |
Microsoft Windows XP Professional | 9.2 TS2M0 | |
Windows Vista | 9.2 TS2M0 | |
Windows Vista for x64 | 9.2 TS2M0 | |
64-bit Enabled AIX | 9.2 TS2M0 | |
64-bit Enabled HP-UX | 9.2 TS2M0 | |
64-bit Enabled Solaris | 9.2 TS2M0 | |
HP-UX IPF | 9.2 TS2M0 | |
Linux | 9.2 TS2M0 | |
Linux for x64 | 9.2 TS2M0 | |
OpenVMS on HP Integrity | 9.2 TS2M0 | |
Solaris for x64 | 9.2 TS2M0 | |