Chapter Contents


SAS/AF Software: Class Dictionary

Using the Variable List Model

You can use the Variable List Model class in conjunction with a viewer control for model/view communication. When you drop a model on a control in a frame, or you set the control's model attribute to the name of the instantiated model object, the items attribute of the view is automatically set to the items attribute of the model when you specify the dataSet attribute on the model.

For example, add a list box control and a variable list model to a frame, then set listbox1.model to variablelist1. To display a list of variables from a data set in the listbox, specify a value for variablelist1.dataSet.

You can also use the variable list model in an SCL program to retrieve a list of variables from a specified SAS table. Once you specify a valid SAS table for the object's dataSet attribute, simply query the items attribute to get the list of variables. To further qualify the selection, specify other attribute values for the object before you query items.

For example, the following code instantiates a variable list model and returns a list of all character variables in the table sasuser.mytable:

  dcl sashelp.classes.variablelist_c.class varobj; 
  dcl list variables; 
  dcl num rc;
  variables = makelist(); 
  varobj = _new_ sashelp.classes.variablelist_c();
  varobj.dataSet = 'sasuser.mytable'; 
  varobj.typeFilter = 'Character';
  variables = varobj.items; 
  call putlist(variables); 
  rc = dellist(variables); 

Working with Variable Names

The Variable List Model items attribute is populated by a list of variables. Each list item is assigned a unique name that is equal to the name of the variable. The unique name appears in the viewer to which you assign the model as long as the model's nameDisplayed attribute is set to Yes.

If nameDisplayed is set to No, the name will not appear in the items attribute list, which means it will not display in any associated view. Each item on the list, however, is a named item that also corresponds to the variable name. You can query the items attribute list using the NAMEITEM function to determine each variable's unique name.

  1. Create a frame with a listbox, variablelist model, and a text label.

  2. Add the following SCL code:

  textlabel1.label=nameitem(Variablelist1.items, Listbox1.selectedIndex);

Chapter Contents



Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.