I would like to give precision about the following affirmation
that Paul made:
"The only reservation I have with your particular
technique is the fact that a format created with the aid of the CNTLIN=
option cannot have the OTHER clause specified ".
This is incorrect, one may add an other clause in a cntlin at the
end of the processing. You must have a "end=eof" flag on your "set lookup".
And you add the following code in your sas datastep :
retain hlo ' ';
if eof then do;
label='other'; /* make it what you want for other */
This last piece of code would add the other clause at the end of your CNTLIN.
I personnaly would use a format with a CNTLIN
for the table lookup problem. It would be easier to maintain and support...
I hope it make it clearer now!
PS: Paul don't feel bad, I have been flamed for less than that!
\\ - - //
( @ @ )
| Bernard Tremblay | |
| La Capitale | Tel: (418) 646-2401 |
| | Fax: (418) 646-5960 |
| | Int: email@example.com |
| Imaginasys enr | Res: (418) 878-4447 |
| | Int: firstname.lastname@example.org |
oooO ( )
( ) ) /
\ ( (_/
>>>From owner-sas-l@UGA.CC.UGA.EDU Wed Apr 1 17:48 EST 1998
>>>Date: Wed, 1 Apr 1998 17:20:37 -0500
>>>Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
>>>From: "Dorfman, Paul" <pdorfma@UCS.ATT.COM>
>>>Subject: (MVS) Re:Re: mvs 6.09e: repeated random read of unsorted flat
>>>Comments: cc: "MICHAEL.RAITHEL@RAITHM49.CUSTOMS.SPRINT.COM"
>>>Michael A. Raithel, in particular, wrote:
>>>> 1. In a new SAS DATA step, ahead of your current program
>>>> logic, read the (very small) 100-record file via an INFILE
>>>> statement. Create the new SAS data set in such a way that
>>>> it can be fed into PROC FORMAT (step #3, below). This is
>>>> done by creating fields:
>>>> start = the lookup key value
>>>> label = the value to be returned in the lookup
>>>> fmtname = the name of the new format
>>>> Since only about 50 records meet your needs, you may decide
>>>> to apply selection criteria to weed out the other 50.
>>>> 2. Sort the SAS data set by the START variable.
>>>> 3. Feed the above SAS data set into PROC FORMAT via the
>>>> CNTLIN= option. This will give you a healthy, happy SAS
>>>> FORMAT for you to use in your "table lookup" macro. You
>>>> would employ the FORMAT in your macro, instead of opening,
>>>> reading, etc. your flatfile.
>>>Methods making use of PROC FORMAT like then method you have proposed are
>>>both the simplest and, as I intend to show below, the quickest and
>>>easiest on resources. The only reservation I have with your particular
>>>technique is the fact that a format created with the aid of the CNTLIN=
>>>option cannot have the OTHER clause specified. As a result, when such a
>>>format - let us call it SRCH., for example, - is used for table lookup
>>>in an expression like LKUP = PUT(KEY, SRCH.), it returns the value of
>>>the KEY if no value for LKUP is found. However, one would expect it to
>>>return some kind of value indicating that a match has failed, and that
>>>could be provided by deliberately coding this value in the OTHER clause.
>>>I would suggest, therefore, that instead of using the CNTLIN= option, a
>>>DATA step writing a PROC FORMAT statememts to a (temporary) file with
>>>the subsequent %inclusion of the latter could be used. Programmatically,
>>>it is hardly more involving but has the added benefit of increased
>>>flexibility . Let us assume, for example, that in a lookup table
>>>containing 1000 entries, the key values LKEY are natural numbers from 1
>>>to 1000, and the lookup values are random natural numbers:
>>>DATA LOOKUP (DROP=I);
>>> DO I=1000 TO &MAX BY 1000;
>>> LKEY = I; LOOKUP = CEIL(RANUNI(1)*1000000); OUTPUT;
>>>Then PROC FORMAT based on this SAS dataset may be created as
>>> FILE TEMP NOPRINT;
>>> IF _N_ = 1 THEN PUT "PROC FORMAT;" / "VALUE SEARCH";
>>> SET LOOKUP END=END;
>>> PUT LKEY "=" LOOKUP;
>>> IF END THEN PUT /"OTHER = .;" / "RUN;";
>>>This code is aching to be macroized with FMTNAME= and OTHER= as macro
>>>Some other table lookup methods have been suggested by a number of
>>>Andreas Grueninger proposed a code utilizing a linear array search;
>>>Peter Crawford mentioned a binary array search "to get started"; Tim