[prev in list] [next in list] [prev in thread] [next in thread]
List: sas-l
Subject: Re: SCL list manipulation (copylist?)
From: Mark Bodt <markbodt () STSS ! CO ! NZ>
Date: 1999-10-31 20:52:17
[Download RAW message or body]
At 16:58 29/10/99 +0100, you wrote:
>I have an external file which looks similar to this:
>a
>a
>b
>c
>a
>c
>
>etc.
>
>what i want to do is create an scl list (resultL) which, given the
above
>file,
>looks like this:
>
>RESULTL ( A= (1 2 5) B=(3) C=(4 6) )
>
>the numbers represent which record numbers the letter was found.
>
<<snip>
Rob,
I quickly wrote the following program which does what you want. That's
not to say that there are not better ways of doing it, but this is a 10
minute solution. I wrote this in V8, but wrote it in V6.12 style so it
should work there too.
<fontfamily><param>SAS Monospace</param><smaller>init:
*avoid compilation warnings;
rc=rc;
*open file;
rc=filename('data',"e:\data.txt");
fid=fopen('data');
*read in data;
*create result list;
resultl=makelist();
*for each record;
recno=1;
do while(fread(fid)=0);
*read in the value;
rc=fget(fid,value,200);
put 'Value read in=' value;
*check that there is a sublist for the value, else create one;
if nameditem(resultl,value)=0 then do;
*sublist does not exist;
sublist=makelist();
*insert the record number into the list;
sublist=insertn(sublist,recno,-1);
*insert the sublist into the result list;
resultl=insertl(resultl,sublist,-1,value);
end;
else do;
*sublist exists;
*get sublist id;
sublist=getniteml(resultl,value);
*insert the record number into the list;
sublist=insertn(sublist,recno,-1);
end;
*increment the record number counter;
recno+1;
end;
*close file;
rc=fclose(fid);
rc=filename('data','');
*list results list;
* call putlist(resultl,'The results list',1);
call putlist(resultl);
*delete temporary lists;
if listlen(resultl)>=0 then rc=dellist(resultl,'Y');
return;
</smaller></fontfamily>Results:
<fontfamily><param>SAS Monospace</param><smaller>(A=(1 2 5 )[7] B=(3 )[9]
C=(4 6 )[11] )[5]</smaller></fontfamily>
+------------------------------------------+--------------------------+
| Mark Bodt | |
| Sunken Treasure Software Systems Ltd | SAS Institute(NZ) Ltd. |
| Specialising in SAS(R) Software | Quality Partner. |
| Consultancy in the Asia / Pacific Region | |
+------------------------------------------+--------------------------+
| PO Box 9472, Marion Square, Wellington, New Zealand |
| Ph (025) 725 386 Fax +64 4 385 8670 Email: markbodt@stss.co.nz |
+---------------------------------------------------------------------+
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic