Validating the Values of Character Attributes

Attributes in SAS/AF software enable you to perform data validation without having to add code to your frame SCL entries. The process behind attribute validation depends on the attribute type and on how you specify some of the attribute metadata.
You can assign a list of valid values to a character attribute. Valid values restrict the value of an attribute to a set of values that you specify for the attribute. The values are stored in the ValidValues metadata item for the attribute. The validation occurs when some action attempts to set the attribute value (that is, when the _setAttributeValue method runs). At build time, the validation is performed when you set the attribute value with the Properties window. At run time, the validation occurs when you assign a new value from SCL code. For example, specifying Yes and No as the valid values for an attribute ensures that only those two values are used at build time and run time.
To define valid values for a component's attribute using the Class Editor:
  1. Select the Attributes node, and then select the character attribute for which you want to add valid values.
    Note: If the attribute is inherited, you must override it by selecting Override from the pop-up menu.
  2. In the Valid Values cell, enter the list of valid values. Use either a space or a comma to separate single-word items, and use a comma (,) to separate multiple-word items. For example,
    Red Blue Green
    or
    Crimson Red, Midnight Blue, Forest Green
    You can also use the Valid Values editor to add valid values. Click the ellipsis (...) button to open the Valid Values editor.
See the SAS/AF online Help for more information on adding valid values in the Class Editor. For more information on the ValidValues metadata item, see Attributes.
Although the Class Editor displays the defined valid values in the combo box that is displayed when you select the Initial Values cell of an attribute, no validation is performed on the initial value that you select. It is the responsibility of the component developer to assign a valid value to the InitialValue metadata item.
You may want to use an SCL entry to perform programmatic validation or to match values against items in an SLIST entry. To assign an SCL or SLIST entry to perform validation for a character attribute, use the Class Editor to set Valid Values to the appropriate entry name. Note that you must preface the catalog entry name with a backslash (\) character.
For example, the defaultAttribute attribute that all components inherit from sashelp.fsp.Object.class has its ValidValues metadata item set to sashelp.classes.defaultattributevalues.scl to run the specified SCL entry when the value of defaultAttribute is set. The SCL entry contains the following code, which returns a list of all attributes that are defined on the object:
/* Include this ENTRY statement to process ValidValues */
entry list:list
      optional= objectId:object
      attributeName:char
      environment:char(2);
dcl num rc;
INIT:
   attributesList=makelist();
   objectID._getAttributes(attributesList, 'Y');
   do i=1 to listlen(attributesList);
      rc=insertc(list, nameitem(attributesList,i), -1);
   end;
   rc=dellist(attributeList, 'Y');
   rc=sortlist(list);
return;
The defaultattributevalues.scl entry executes when the defaultAttribute attribute of any object is set. For details on the ENTRY statement used in this example, see Creating a Custom Attribute Editor.
You can also use a custom access method to process valid values for an attribute. For more information on custom access methods, see Assigning a Custom Access Method (CAM) to an Attribute.