![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
The DATA step Component Interface creates and manipulates component objects from within a DATA step program. One such object is the Javaobj, which provides a mechanism, similar to the Java Native Interface (JNI), for instantiating Java classes, and accessing fields and methods on the resultant objects.
Note: The DATA step Java object is production in SAS 9.2. It was preproduction in SAS 9.0 and 9.1.
This sample demonstrates how to use the Javaobj and the DATA step Component Interface to implement a basic calculator that can be called from your DATA Step code.
Tip: The Downloads tab also includes a link to the Java code for Calculator class written for this sample.
C:\JavaPgms\samples.jar. After the CLASSPATH is set, SAS Foundation will have access to any programs that are contained within the JAR file.
Note: For instructions on how to set environment variables, see your operating system 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.
data _null_;
declare javaobj calculator("samples/calc/Calculator");
put 'Demonstrating Basic operations';
x = 5; y = 3;
calculator.callStaticDoubleMethod("add",x,y,sum);
put ' ' x '+ ' y '= ' sum;
calculator.callStaticDoubleMethod("subtract",x,y,difference);
put ' ' x '- ' y '= ' difference;
calculator.callStaticDoubleMethod("multiply",x,y,product);
put ' ' x '* ' y '= ' product;
calculator.callStaticDoubleMethod("divide",x,y,quotient);
put ' ' x '/ ' y '= ' quotient;
put ;
put 'Demonstrating Memory operations';
calculator.callDoubleMethod("memoryRecall",memory);
put ' Memory Recall: ' memory;
calculator.callVoidMethod("memoryPlus",5);
put ' Memory Plus (5)';
calculator.callVoidMethod("memoryPlus",3);
put ' Memory Plus (3)';
calculator.callDoubleMethod("memoryRecall",memory);
put ' Memory Recall: ' memory;
calculator.callVoidMethod("memoryMinus",2);
put ' Memory Minus (2)';
calculator.callDoubleMethod("memoryRecall",memory);
put ' Memory Recall: ' memory;
calculator.callVoidMethod("memoryClear");
put ' Memory Clear';
calculator.callBooleanMethod("hasMemory",memflag);
put ' Memory Stored (0=false, 1=true)? ' memflag;
calculator.callDoubleMethod("memoryRecall",memory);
put ' Memory Recall: ' memory;
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.
Demonstrating Basic operations 5 + 3 = 8 5 - 3 = 2 5 * 3 = 15 5 / 3 = 1.6666666667 Demonstrating Memory operations Memory Recall: 0 Memory Plus (5) Memory Plus (3) Memory Recall: 8 Memory Minus (2) Memory Recall: 6 Memory Clear Memory Stored (0=false, 1=true)? 0 Memory Recall: 0
Download and extract samples.zip to the computer on which your SAS Foundation installation is executing.
(To see the Java code for the Calculator class, download the calculator.java file.)
| Type: | Sample |
| Topic: | SAS Reference ==> Component Objects ==> Component Objects |
| Date Modified: | 2009-02-12 13:31:04 |
| Date Created: | 2009-01-27 18:08:23 |
| Product Family | Product | Host | SAS Release | |
| Starting | Ending | |||
| SAS System | SAS Foundation | z/OS | 9.2 TS1M0 | |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS1M0 | |||
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS1M0 | |||
| Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS1M0 | |||
| Microsoft Windows XP 64-bit Edition | 9.2 TS1M0 | |||
| Microsoft® Windows® for x64 | 9.2 TS1M0 | |||
| Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS1M0 | |||
| Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS1M0 | |||
| Microsoft Windows Server 2003 Standard Edition | 9.2 TS1M0 | |||
| Microsoft Windows XP Professional | 9.2 TS1M0 | |||
| Windows Vista | 9.2 TS1M0 | |||
| 64-bit Enabled AIX | 9.2 TS1M0 | |||
| 64-bit Enabled HP-UX | 9.2 TS1M0 | |||
| 64-bit Enabled Solaris | 9.2 TS1M0 | |||
| HP-UX IPF | 9.2 TS1M0 | |||
| Linux | 9.2 TS1M0 | |||
| Linux for x64 | 9.2 TS1M0 | |||
| OpenVMS on HP Integrity | 9.2 TS1M0 | |||
| Solaris for x64 | 9.2 TS1M0 | |||





