The FCMP Procedure |
Introduction to the FCmp Function Editor |
SAS language functions and CALL routines that are created with PROC FCMP are stored in SAS data sets that are contained in package declarations. Each package declaration contains one or more functions or CALL routines. The FCmp Function Editor displays all of the functions and CALL routines that are included in a package.
With the FCmp Function Editor, you can view functions in a package declaration as well as create new functions. You can add these new functions to an existing package, or create a new package declaration.
Open the FCmp Function Editor |
If you are working in the Windows operating environment and SAS is installed locally on your computer, the sign-on dialog box is bypassed because Windows supports single sign-on functionality.
If you are not working in the Windows operating environment, or if you do not have SAS installed locally, then you will be prompted for your authorization credentials, which are your user ID and password.
To open the FCmp Function Editor, select Solutions Analysis FCmp Function Editor from the menu in your SAS session. The following dialog box appears:
Initial Dialog Box for the FCmp Function Editor
After you enter your user ID and password and click Log On, SAS establishes a connection to a port. The following window then appears:
The FCmp Function Editor with Libraries Displayed
In the window above, you can see that the left pane lists the functions that are in the SASHELP and SASUSER libraries. The WORK library is empty. You cannot access the WORK library directly from a spawning SAS session. The FCmp Function Editor remaps the WORK library from the spawning SAS session to the location of OLD_WORK so that you can access the contents of WORK from OLD_WORK.
Working with Existing Functions |
To open a function, select a library from the left pane, expand the library, and drill down until a list of functions appears. Double-click the name of the function you want to open.
If you open a function from a read-only library, a window similar to the following appears:
A Function in a Library That Has Read-Only Access
In the window above, the ARMORLINK_SLK function is selected from the read-only SASHELP library. Use the scrollbar to scroll to the top of the function.
If you open a function from a library to which you have write access, a window similar to the following appears:
A Function in a Library That Has Write Access
In the window above, SUBTRACT_MACRO is selected from the write-enabled SASUSER library.
Use the scrollbar to scroll to the top of the function.
You can see that there is a difference in the windows that display depending on whether the library has read-only access or write access. If the library has write access, you can enter information in the top section of the window you are viewing. These fields are the same fields you use when you create a new function. For a description of the fields, see Creating a New Function.
If you do not change the function name, the function is moved from its original position in the hierarchy to the library, data set, or function package that you designate.
Opening multiple functions results in multiple windows being opened. For example, if you open a second function, a second window displays that shows the code for that function.
The upper right corner of the FCmp Function Editor window contains a field called Open Views. Click the arrow to list the functions that are open. When you select a function, the window for that function is brought to the foreground.
Two icons that you can use to alter the display of your functions are located at the left of the Open Views field:
|
cascades the display of the functions that are open. |
|
arranges the functions to display side by side. |
You can move a function to a different library, data set, or package by first opening a function in a library that has write access. Then enter information for the fields that display at the top section of the window.
You can also highlight a function, right-click, and select Move from the menu. The following dialog box appears:
The Move Dialog Box
In the Move dialog box, you can do the following:
enter a new name for the function
select a library into which the function is to be moved
enter a new data set name
enter a Package name
The descriptions of the fields in the Move Dialog box are as follows:
Name |
specifies the new name for the function. |
Library |
specifies the library that will contain the function that you copy. Use the menu in the Library field to select a library. |
Dataset |
specifies the data set that will contain the function that you copy. Enter the name of the data set, or click the down arrow in the Dataset field to select a data set. If you do not choose a data set, then the value in this field defaults to Functions. |
Package |
specifies the name of the package that will contain the new function that you copy. Enter the name of the data set, or click the down arrow in the Package field to select a data set. If you do not choose a data set, then the value in this field defaults to Package. |
When you click OK, the following dialog box appears, cautioning you about the move:
The Move Function Confirmation Dialog Box
Click Yes or No.
When you right-click the function name in the left pane and select Close, the window that displays that function closes. You can also close the function by clicking OK in the bottom right corner of the window.
You can copy a function that you are viewing to an existing or new package or library to which you have write access. To do this task, click the function name in the left pane to select it, and then right-click the function name and select Duplicate from the menu. The following dialog box appears:
The Duplicate Function Dialog Box
The fields in this dialog box automatically display the function name, library, data set, and package of the function you want to copy. You can change these fields when you copy the function.
For a description of these fields, see Move a Function.
To export a function to a file, click a function name in a library to select the function. Then right-click the function and select Export to File from the menu. At the top of the Save dialog box that appears, you can see the current location of the function, (for example, SASUSER.EXSUBS.pkt1.calc-years). The function CALC-YEARS resides in the package called pkt1, in the data set EXSUBS, in the SASUSER library.
In the Save in field, select the directory to which you want the function exported.
Use the Rename dialog box to rename a function within a given package. You must have write access to the library that contains the function. When you rename a function, the new function resides in the same library as the original function.
To rename a function, first select the function and then right-click the function and select Rename from the menu. The following dialog box appears:
The Rename Dialog Box
Enter the new name of the function and click OK.
You can delete a function from a library to which you have write access. To delete a function, first select the function you want to delete. Right-click the function and select Delete from the menu. The following dialog box appears, cautioning you about the impact that Delete has on other items:
Delete Function Confirmation Dialog Box
Click Yes or No.
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 File New Function from the menu or click
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 data set, or click the down arrow in the Library field to select a library. |
Dataset |
specifies the data set that will contain the new function. Enter the name of the data set, or click the down arrow in the Dataset 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 data set, or click the down arrow in the Package field to select a data set. 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:
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. In this example, the function newFunction was created with a Kind value of Project, in the package math, in the data set FUNCS, and in the WORK library. |
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. |
Two tabs are located at the bottom left of the newElement window:
Details tab |
provides you with an area in which to write descriptive information (name of the new function, list of include libraries, input parameters, and so forth) about your function. You code your new function in the Function Body section. The Details tab is selected by default. |
SAS Code tab |
enables you to view the function you have written. The SAS Code selection provides read-only capabilities. |
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 tab.
The newElement window contains a Check Syntax button that is located at the bottom of the two tabs. When you click this button, SAS checks the syntax of the function that you wrote. If the syntax contains an error, the following dialog box appears:
Program Error Dialog Box
You are instructed to check the log for errors. To check the log, select View Show Log from the menu.
Viewing the Log Window, Function Browser, and Data Explorer |
You can display the log window by selecting View Show Log from the menu. The content of the log represents output from the SAS server. In addition, commands that are sent to SAS are also present to add context to the log output.
When you display the Log window, you can view system, application, and program results by selecting the tabs that are located in the upper left corner of the window. The following display shows the Log window with the SAS log displayed:
The Log Window
You can see different results when you select the following tabs:
System tab |
displays the System window. Detailed information in the form of system messages is located here. The window will be blank if no messages are logged. The System window contains two vertical tabs that are located in the upper right section of the window. These tabs provide complete information about messages that might be of interest:
| ||||
Application tab |
displays the processing messages for the application. | ||||
SAS tab |
displays the execution results in the SAS log. |
You can save the log results to a file, and then clear the System, Application, and Log results. Three buttons that are located at the bottom right of the Log window enable you to perform these tasks:
Save Log |
saves the log output to a file that you choose in your directory. |
Clear One |
clears the results in the active window. |
Clear All |
clears the results in all three of the windows. |
The Find button is located at the bottom left of the window. Use this button to search through your text to find a string that you entered in the Find field.
The Function Browser initially displays all of the functions that are listed in the left pane of the window. You can filter this list of functions to display a subset of the functions.
You display the Function Browser by selecting View Show Function Browser from the menu. A window similar to the following appears:
The Function Browser Window
The output listed above shows all of the functions in the application tree. You can filter the output and create a subset of the functions by entering your criteria in the Function Browser fields that are located above the list of functions, These fields are Library Name, Dataset Name, Package Name, and Function Name.
The following display shows that three fields are filled in. When you press the OK button that is located in the bottom right corner of the window, or if you press the Find button that is located in the upper right corner, the following window appears:
Filtered Output from the Function Browser
The functions that are listed are located in the SASUSER library, the FUNCS data set, and the math package.
You can enter information in the fields you choose. For example, if you enter a value in the Library Name field only, then all of the functions that are in the SASHELP library display.
The Data Explorer enables you to view the data in a data set that you select. To display the Data Explorer, select View Show Data Explorer from the menu. A window similar to the following appears:
The Data Explorer Window
The Data Explorer window displays data set information based on which data set you select from the left pane.
By clicking the column headings, you can move the columns to reposition them in the display. When you click OK in the lower right section of the window, the changes you made are saved.
Using the Function You Select in Your DATA Step Program |
For an example of how PROC FCMP and DATA step syntax work together, see Directory Transversal.
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.