![]() Chapter Contents |
![]() Previous |
![]() Next |
| SAS Component Language: Reference |
class x; endclass;Enter the above code in an SCL entry such as X.SCL and then create the class by using the SAVECLASS command. You should now see a CLASS entry for X in the current catalog.
To add functionality to this class, you can create a simple method by using the following code:
class x;
m: method;
put 'Hello';
endmethod;
endclass;The PUT statement will write Hello to
the SAS procedure output file or to a file that is specified in the most recent
FILE statement. To run this method, you need to create an example of the class
and call the method. In an SCL entry called Y.SCL, enter the following code:
init:
dcl x x = _new_ x();
x.m();
return;The _NEW_ operator is used to create an example of the class X and
to assign it to the variable x. The _NEW_ operator
provides a faster and more direct way to create an object by combining the
actions of loading a class with LOADCLASS and initializing the object with
the _new method, which invokes the object's _init method. You then call method
M using the object variable x in the dot notation
expression x.m().
Note:
dot notation provides a shortcut for invoking
methods and for setting or querying attribute values. Using dot notation reduces
typing and makes SCL programs easier to read. It also enhances run-time performance
if you declare the object used in the dot notation as an example of a predefined
class instead of a generic object. The object's class definition is then known
at compile time. Because dot notation checks the method signature, it is the
only way to access an overloaded method as illustrated in Overloaded Methods _ Level Two. ![[cautend]](../common/images/cautend.gif)
Compile Y.SCL, and then use the TESTAF command to run it. You should see the following output:
Hello
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.