SAS Component Language Dictionary |
Category: | List |
Syntax | |
Details | |
Examples | |
Example 1: Using the POPC Function | |
Example 2: Using the POPL Function | |
Example 3: Using the POPN Function | |
Example 4: Using the POPO Function | |
See Also |
Syntax |
cval=POPC(list-id<,index>); |
sublist-id=POPL(list-id<,index>); |
nval=POPN(list-id<,index>); |
obj-id=POPO(list-id<,index>); |
contains the character value that was removed from the list by POPC.
contains the identifier of the sublist that was removed from the list by POPL.
contains the numeric value that was removed from the list by POPN.
contains the identifier of the object item that was removed from the list by POPO.
contains the identifier of the list from which the value or sublist is removed. An invalid list-id produces an error condition.
is the position of the item in the list. The position can be specified as a positive or negative number. By default, index is 1 (the first item). If index is a positive number, then the item is at position index from the beginning of the list. If index is a negative number, then the item is at position ABS(index) from the end of the list. An error condition results if the absolute value for index is zero or if it is greater than the number of items in the list.
Details |
These functions are useful for implementing stacks and queues of values.
the specified item is not a character item and you use POPC, the item is not a sublist and you use POPL, the item is not numeric and you use POPN, or the item is not an object and you use POPO.
To check the attributes of a list or list item, use HASATTR. To change attributes, use SETLATTR. Use ITEMTYPE to test the type of an item when the list contains items with types other than the one for which you are searching.
Examples |
These examples assume that all list items are character. Programs A and B are equivalent. Both remove the last item in an SCL list.
A: cval1=popc(listid,-1); put cval1=; B: cval2=getitemc(listid,-1); put cval2=; listid=delitem(listid,-1);
This example creates an SCL list called TODOQ, which represents a queue of tasks to do. A SAS/AF FRAME entry has a text entry named NEWTASK for entering a new task into the TODOQ queue. A second text entry, TODO, displays the first task in the to-do queue. A DONE button removes the top task from the TODOQ queue.
INIT: todoq = makelist(); done._gray(); return; NEWTASK: todoq = insertc(todoq, newtask.text, -1); /* Enqueue */ newtask.text = ''; cursor newtask; return; DONE: /* Dequeue */ finished = popc(todoq); return; MAIN: if listlen(todoq) then do; done._ungray(); todo.text = getitemc(todoq); end; else do; done._gray(); todo.text = ''; end; return; TERM: rc = dellist(todoq); return;
This program searches for, retrieves, and deletes the first sublist item from the list LISTID:
LOOP: do i=1 to listlen(listid); if itemtype(listid,i)='L' then do; list=popl(listid,i); leave loop; end; end; ...other SCL statements...
This example creates a new list called DATETIMES and treats it as a stack. The entry displays SAS datetime values when the button PUSH is pressed. The text entry pops and displays SAS datetime values from the DATETIMES stack when the button POP is pressed.
INIT: datetimes = makelist(); pop._gray(); return; PUSH: datetime.value = datetime(); datetimes = insertn(datetimes, datetime.value); pop._ungray(); return; POP: datetime.value = popn(datetimes); if listlen(datetimes) = 0 then pop._gray(); return; TERM: rc = dellist(datetimes); return;
This example inserts an object into an SCL list and then removes the object from the list:
DCL sashelp.fsp.object.class obj1; DCL object obj2; init: obj1=_new_ sashelp.fsp.object.class(); l1 = makelist(); l1 = inserto(l1,obj1); /* Insert object as first item of list */ obj2 = popo(l1); /* Remove object from the list into obj2 */ return;
See Also |
GETITEMC, GETITEML, GETITEMN, and GETITEMO
INSERTC, INSERTL, INSERTN, and INSERTO
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.