Chapter Contents |
Previous |
Next |
POPC, POPL, POPN, and POPO |
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>); |
Type: Character
Type: List
Type: Numeric
Type: Object
Type: List
Type: Numeric or List
Details |
These functions are useful for implementing stacks and queues of values.
An error condition results if
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
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.