LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2007, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 4 Sep 2007 12:59:45 -0400
Reply-To:   Paul Dorfman <sashole@BELLSOUTH.NET>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Paul Dorfman <sashole@BELLSOUTH.NET>
Subject:   Re: hash add method
Comments:   To: "Richard A. DeVenezia" <rdevenezia@WILDBLUE.NET>

Richard,

It appears as though when a hash definition contains DefineKey('key') but contains no DefineData() at all, DefineData('key') is added implicitly. That explains why OUTPUT() method seems to write keys out, in fact writing the data, not the keys - the inviolable rule is that keys are neither written to PDV host variables, hence nor are they written out with OUTPUT() method. That also explains why your error causes the following info in the log:

ERROR: Incorrect number of data entries specified at line ... column 1.

which seemed to indicate that ADD() method expects both key and data to be given via the tags, but you have given the key only. Obliquely, it is confirmed by the fact that when I change S.add(key:'c') to S.add(key:'c',data:'c'), it works hunky-dory, and the error vanishes.

As to S.add(), it works trouble-free because the value of ELEMENT in the PDV provides the values for both the key and the data portion of the hash.

Kind regards ------------ Paul Dorfman Jax, FL ------------

On Tue, 4 Sep 2007 11:14:58 -0400, Richard A. DeVenezia <rdevenezia@WILDBLUE.NET> wrote:

>Oft times a hash is simply used to test if a value is in some set. > >What I find peculiar is that when a hash has only keys, the .ADD method >cannot be used if the key: tag is utilized! > >data _null_; > > declare hash S(); > S.defineKey('element'); > S.defineDone(); > > element = 'a'; > S.add(); > element = 'b'; > S.add(); > > if S.find(key:'c') ne 0 then > put "'c' is not in S"; > > * key: tag causes an error !; > S.add(key:'c'); > > if S.find(key:'c') eq 0 then > put "'c' is in S"; > > stop; >run; > >Does such an error seem reasonable ? Not to me :( > >Another interesting quirk, when a hash has only keys, the OUTPUT method >writes out the key values. When a hash hash keys and data, only the data is >written out. > >-- >Richard A. DeVenezia


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