Chapter Contents

Previous

Next
SAS/AF Software: Class Dictionary

Using the Data Set List Model

You can use the Data Set 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 library attribute on the model.

For example, add a list box control and a data set list model to a frame, then set listbox1.model to datasetlist1. To display a list of data sets (or tables) in the listbox, specify a value for datasetlist1.library.

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

For example, the following code instantiates a data set list model and returns a list of all SAS data sets in the library sasuser:

init: 
  dcl sashelp.classes.datasetlist_c.class tablobj; 
  dcl list tables; 
  dcl num rc;
  tables = makelist(); 
  tablobj = _new_ sashelp.classes.datasetlist_c();
  tablobj.library = 'sasuser'; 
  tablobj.levelCount = 1; 
  tables = tablobj.items;
  call putlist(tables); 
  tablobj._term(); 
  rc = dellist(tables);
return;
Since levelCount is set to 1, only the data set name is returned in the items list. If levelCount is set to 2, the two-level name (such as sasuser.mytable) is returned.

Working with Data Set Names

The Data Set List Model items attribute is populated by a list of data sets. Each list item is assigned a unique name that is equal to libname.dataset. The unique name appears in the viewer to which you assign the model as long as the model's SASFileDisplayed attribute is set to Yes.

If SASFileDisplayed 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 data set name. You can query the items attribute list using the NAMEITEM function to determine each data set's unique name.

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

  2. Add the following SCL code:

listbox1:
  textlabel1.label=nameitem(Datasetlist1.items, Listbox1.selectedIndex);
return;


Chapter Contents

Previous

Next

Top of Page

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