![]() Chapter Contents |
![]() Previous |
![]() Next |
| SAS Component Language: Reference |
For example, consider the following class, which uses SCL lists to maintain data:
class lst supported reader;
private list l;
private num nvars;
private num nelmts;
private num cur;
/* Constructor */
lst: method n:num;
l = makelist();
nvars = n;
nelmts = 0;
cur = 1;
endmethod;
/* Copy method */
cpy: method n: num return=string;
dcl string c = "";
if (cur <= nelmts) then do;
c = getitemc(l, cur);
cur + 1;
end;
return c;
endmethod;
/* Read method */
read: method return=num;
if (cur > nelmts) then
return 1;
else
return 0;
endmethod;
/* Add an element to the list */
add: method c:string;
nelmts + 1;
setitemc(l, c, nelmts, 'Y');
endmethod;
/* Add two elements to the list */
add: method c1:string c2:string;
add(c1);
add(c2);
endmethod;
/* Terminate the list */
_term: method /(state='O');
if (l) then dellist(l);
_super();
endmethod;
endclass;This class represents a list, and because it supports the READER interface,
it can be read in the same way as the DDATA and FDATA classes.
The SCL for reading from the list is
init:
dcl lst l;
dcl read r;
l = _new_ lst(2);
/* Notice the overloaded add method */
l.add("123", "456");
l.add("789", "012");
l.add("345", "678");
/* Create a read class and loop over the data */
r = _new_ read(l);
r.loop();
r._term();
return;The output for this program will be
123 456 789 012 345 678
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.