Sample 26159: Macro Tool to Handle Multiple Names
The need to handle name/value pairs where there may be multiple values is a common occurrence. A good way to handle such values is to use a macro tool, instead of including the code in each program. Such a macro, multipleNames, is provided as part of the sample environment. This macro can serve as the basis for such a tool. It handles multiple names by doing several things:
- ensuring that the Suffix 0 variable always exists with the following values:
- a value of 0 if the field is not defined (e.g., multiple check boxes with the same name and none selected)
- a value of 1 if only one value is defined
- ensuring that the Suffix 1 variable always exists and has the same value as the field without the suffix (allowing the program to always refer to the Suffix 1 variable)
- allowing for an option to collapse all the values into a single space-delimited field (e.g., if multiple name/value pairs are used for a variable list)
|
|
Best Practice: Define and use an autocall macro that is available to the Application Server that handles multiple name/value pairs. Define the autocall location using the sasautos option in the program specified in the REQUEST INIT= parameter.
|
|
It can be called repeatedly in the same program if, for example, some names are to be collapsed to a single name and some are not.
The options for the macro include the following:
- the list of parameter names that can potentially have multiple values.
- a parameter (singleList) that specifies whether the multiple values are to be collapsed into a single space-delimited field. A non-blank value turns this option on.
To see an example of the features of the multipleNames macro, go to the sample environment located at http://hcsbi.com/IntrNetAppDev/ and select Chapter 5. Then select Demo multipleNames Macro. Try the following combinations (plus others) to determine how to use the maro.
- Select no values and note how the macro creates macro variables for both the original name and the Suffix 1 name. That allows the program code to refer to either the original name or the Suffix 1 name. Note how the Suffix 0 variable has a value of 0. When used in the upper bound of a DATA step or macro DO loop, the loop is never be entered.
- Select only one value for one or more of the fields and note how the values are set. Again the original name and the Suffix 1 name both exist and have the same value, which means that the Suffix 1 value exists.
- Select more than one value.
- When selecting more than one value, also check the check box to Combine into a single field and note that the variables with the suffixes have each individual value, while the original name, as a result of the macro execution, includes them all as a space-delimited list. Also use this option with the radio box option to print the SASHELP.CLASS data set.
Figure 5.1 shows the output produced when three check boxes (used to specify the variables to include) are selected from the above link.
About the Author
Don Henderson is the Owner and Principal of Henderson Consulting Services, a SAS Affiliate Partner. Don has used SAS software since 1975, designing and developing business applications with a focus on data warehouse, business intelligence, and analytic applications. Don was one of the primary architects in the initial development and release of SAS/IntrNet software in 1996, and he was one of the original developers for the SAS/IntrNet Application Dispatcher. Don has presented numerous papers at SUGI and regional SAS user group meetings, and continues to be a great supporter of SAS and its products.
His book is available from the online bookstore.
The need to handle name/value pairs where there may be multiple values is a common occurrence. A good way to handle such values is to use a macro tool, instead of including the code in each program. This tip submitted by Don Henderson.
| Type: | Sample |
| Topic: | Internal Administration ==> BBU
|
| Date Modified: | 2007-05-02 03:03:15 |
| Date Created: | 2007-05-02 03:03:15 |
Operating System and Release Information
| SAS System | SAS/IntrNet | All | 8 TS M0 | 9.1 TS1M3 |