Chapter Contents

Previous

Next
DATALISTC and DATALISTN

DATALISTC and DATALISTN



Displays a selection list window that contains the values of particular columns from rows in a SAS table and returns user selections

Category: SAS Table


Syntax
Details
Examples
Example 1: Using DATALISTC to Return a Single Selection
Example 2: Using DATALISTN to Return Multiple Selections
See Also

Syntax

selection=DATALISTC(table-id,
col-list<,message<,autoclose<,num-sel>>>);
selection=DATALISTN(table-id,
col-list<,message<,autoclose<,num-sel>>>);

selection
is the value of the first column from the selected row. For DATALISTC, the value is the first character column. For DATALISTN, the value is the first numeric column. Selection is a missing value (period) if the user closes the selection list window without making a selection.

For DATALISTC, selection is blank if the selection list window is closed and no selections are made. By default, selection is 200 bytes long. To accommodate a value longer than 200 bytes, explicitly declare selection with a longer length.

Type: Character, Numeric.

table-id
is the identifier that was assigned when the table was opened. If table-id is invalid, the program halts.

Type: Numeric

col-list
is a list of column names, separated by blanks, from the SAS table to be displayed. For DATALISTC, the first column in this list must be character or else the program halts. For DATALISTN, the first column must be numeric or else the program halts. However, the remaining columns in the list can be of any type.

Type: Character

message
is the text for a message to be displayed above the selection list. The default message tells users to make up to the number of selections specified in num-sel.

Type: Character

autoclose
specifies whether the selection list window closes automatically after a user makes a selection when only one choice is allowed:
'Y' closes the window automatically. (This is the default.)
'N' leaves the window open until the user explicitly closes it.

This option is ignored when num-sel is not 1. However, use '' as a placeholder if you are also specifying a value for num-sel.

Type: Character

num-sel
specifies the maximum number of items a user can select from the list. To display the list for information purposes only (no selections allowed), specify 0. To specify unlimited selections, use a value that is larger than the number of available selections, such as 9999.

Type: Numeric


Details

If a user ends the selection list window without making a selection, DATALISTC and DATALISTN return a blank value. If the user exits by using [OK]without making a selection, then the selection variable is set to blank. However, if the user exits using [CANCEL] without making a selection, the selection variable retains any previous value it may have had.

Although a user can position the cursor or mouse pointer anywhere in a row to make a selection from the list, only the value of the first column is returned. (The other column values are displayed for information only.)

When multiple selections are allowed, selection contains only the value of the first column in the last selected row. However, values for displayed columns for all rows that are selected can be returned in the current result list if one is available. The current result list is a special SCL list that is automatically filled with the values selected from a selection list. To create a current result list, use the MAKELIST function to create it, and use the CURLIST function to designate it as the current result list. The current result list must exist before you call the DATALISTC or DATALISTN function.

By default, a message is displayed asking the user to make one selection, and the selection list window closes automatically when the user makes a selection.

When DATALISTC or DATALISTN is invoked, the current result list is cleared. After DATALISTC or DATALISTN is invoked, the result list contains the following named items:

TAG
identifies the list as one that was created by the DATALISTC function.

Type: Character

COUNT
contains either the number of selected elements, or 0 if a user makes no selections or issues a CANCEL command in the list window.

Type: Numeric

var-name
contains the value of column var-name in var-list for each selection.

Type: Numeric or Character


Examples

Example 1: Using DATALISTC to Return a Single Selection

Create a selection list whose rows contain the values of the columns NAME, STREET, CITY, STATE, and ZIP from the SAS table identified by the SCL variable CLASSID, which was returned by the OPEN function. NAME contains the value for the selected row. The other columns are displayed for information purposes only.

name=datalistc(classid,'name street city state zip');

Example 2: Using DATALISTN to Return Multiple Selections

Create a selection list whose rows contain the values of the columns ITEMNUM, ITEMAMT, CUSTNAM, and CUSTADR from the SAS table identified by the SCL variable SALESID. Allow users to make up to three selections from this selection list. Then retrieve the values for each column for each of the selected rows from the current result list.

salesid=open('sales');
listid=makelist();
rc=curlist(listid);
itemnum=datalistn(salesid,
  'itemnum itemamt custnam custadr','','',3);
n=getnitemn(listid,'COUNT');
do i=1 to n;
   itemnum=getnitemn(listid,'ITEMNUM',i);
   itemamt=getnitemn(listid,'ITEMAMT',i);
   custnam=getnitemc(listid,'CUSTNAM',i);
   custadr=getnitemc(listid,'CUSTADR',i);
   put itemnum= itemamt= custnam= custadr=;
end;
rc=close(salesid);

See Also

LISTC and LISTN

LOCATEC and LOCATEN

SHOWLIST

VARLIST


Chapter Contents

Previous

Next

Top of Page

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