LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (April 1998, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 1 Apr 1998 18:05:36 +0500
Reply-To:   Bernard Tremblay <bernard@CAPITALE.QC.CA>
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   Bernard Tremblay <bernard@CAPITALE.QC.CA>
Subject:   Re: (MVS) Re:Re: mvs 6.09e: repeated random read of unsorted flat
Comments:   To: pdorfma@UCS.ATT.COM
Comments:   cc: bernard@pollux.CC.UGA.EDU

Hi,

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 ' '; output; if eof then do; hlo='O'; start=' '; label='other'; /* make it what you want for other */ end=' '; output; end;

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!

Bernard Tremblay

PS: Paul don't feel bad, I have been flamed for less than that!

\\\|/// \\ - - // ( @ @ ) +------oOOo-(_)-oOOo----------+---------------------------------+ | Bernard Tremblay | | | La Capitale | Tel: (418) 646-2401 | | | Fax: (418) 646-5960 | | | Int: bernard@capitale.qc.ca | +-----------------------------+---------------------------------+ | Imaginasys enr | Res: (418) 878-4447 | | | Int: bertrem@quebectel.com | +---------------Oooo----------+---------------------------------+ oooO ( ) ( ) ) / \ ( (_/ \_) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>>From owner-sas-l@UGA.CC.UGA.EDU Wed Apr 1 17:48 EST 1998 >>>X-Priority: 3 >>>Mime-Version: 1.0 >>>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.RAITHEL@RAITHM49.CUSTOMS.SPRINT.COM> >>>To: SAS-L@UGA.CC.UGA.EDU >>>Content-Type: text/plain >>>Content-Length: 2834 >>> >>>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; >>> END; >>>RUN; >>> >>> >>>Then PROC FORMAT based on this SAS dataset may be created as >>> >>> >>>DATA _NULL_; >>> 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;"; >>>RUN; >>> >>> >>>This code is aching to be macroized with FMTNAME= and OTHER= as macro >>>parameters... >>> >>> >>>Some other table lookup methods have been suggested by a number of >>>posters: >>>Andreas Grueninger proposed a code utilizing a linear array search; >>>Peter Crawford mentioned a binary array search "to get started"; Tim >>>Berryhill


Back to: Top of message | Previous page | Main SAS-L page