Creating a New Function

You can create a new function whenever you have a library, data set, or package selected. To create a new function in a library, position your cursor on the library into which the new function will be added. Right-click the library and select New Function. You can also select Filethen selectNew Function from the menu or clickicon in the upper left corner below the menu bar. The following window appears:
The newElement Window
The newElement Window
The upper right corner of the window contains two buttons: Function and Subroutine. Click one of the buttons depending on whether you want to create a new function or a new subroutine.
The newElement window contains the following fields:
Name
specifies the name of the new function.
Description
describes the new function.
Library
specifies the library that will contain the new function. Enter the name of the library, or click the down arrow in the Library field to select a library.
Data Set
specifies the data set that will contain the new function. Enter the name of the data set, or click the down arrow in the Data Set field to select a data set. If you do not specify a value, the value in this field defaults to Functions.
Package
specifies the name of the package that will contain the new function. Enter the name of the package, or click the down arrow in the Package field to select a package. The Package field is a required field. If you do not specify a value, the value in this field defaults to Package.
Kind
enables you to group functions within a given package. Four predefined kind groupings are available and are typically used with SAS Risk Management:
  • Project
  • Risk Factor Transformation
  • Instrument Pricing
  • Instrument Input
You can use one of these four groupings, or enter your own kind value in the Kind field. The function tree in the left pane groups the functions in a package into their kind grouping, if you specified a value for Kind.
Include Libraries
specifies libraries that contain SAS code that you want to include in your function.
Input Parameters
specifies the arguments that you use as input to the function.
Variable Parameter List
specifies whether the function supports a variable number of arguments.
Return Type
specifies whether the function returns a character or numeric value.
Function Body
is the area in the window in which you code your function.
Three buttons are located at the bottom left of the newElement window:
Details
provides you with an area in which to write descriptive information (name of the new function, list of include libraries, input parameters, and so on) about your function. You code your new function in the Function Body section. The Details tab is selected by default.
SAS Code
enables you to view the function that you have written. The SAS Code selection provides read-only capabilities.
Check Syntax
enables you to check the syntax for the code that you have written. If the syntax is correct, a dialog box appears stating that the syntax is correct. If the syntax contains an error, a dialog box appears that describes the error. An error message also appears in the lower left bar of the window. Syntax errors are written to the log, which you can access from the Viewthen selectShow Log menu.
When you enter information in the descriptive portion of the Details tab, as well as in the Function Body section, the information is converted to SAS code that you can see when you select the SAS Code button.