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 (August 2003, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 26 Aug 2003 18:36:49 +0000
Reply-To:     sashole@bellsouth.net
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Paul Dorfman <paul_dorfman@HOTMAIL.COM>
Subject:      Re: Ways to code (if Var contains the value of an Obs in another
              SAS dataset).
Comments: To: yhuang@AMYLIN.COM
Content-Type: text/plain; format=flowed

Ya,

Nope, it is a very old trick I bet you have already seen. Sometimes it referred to as macro array, but I think the term is confusing. The simple truth is that since the ability to look macro variables by name in the symbol table is embedded in the macro processor, you can store key values as macro variable names - most often, via CALL SYMPUT() or SQL with INTO: - and the satellite(s) - as those macro variables' values. Then at the time of search, supply a search key to SYMGET(), and extract the satellite info. Of course the key values themselves cannot be just anything: They have to conform to the rules of a valid SAS names. This leaves us with 31-byte alphanumeric keys because to avoid the situation when it begins with a digit, it makes sense to precede it with an underscore. As an illustration, try, say,

data lookup ; input state: & $char31. nickname: & $char30. ; call symput ('_' || translate (state, '_', ' ') , nickname) ; cards ; Alabama Yellowhammer State Alaska The Last Frontier Arizona Grand Canyon State Arkansas The Natural State California Golden State Colorado Centennial State Connecticut Constitution State Delaware First State Florida Sunshine State Georgia Peach State Hawaii Aloha State Idaho Gem State Illinois Prairie State Indiana Hoosier State Iowa Hawkeye State Kansas Sunflower State Kentucky Bluegrass State Louisiana Pelican State Maine Pine Tree State Maryland Free State Massachusetts Bay State Michigan Wolverine State Minnesota North Star State Mississippi Magnolia State Missouri Show-me State Montana Treasure State Nebraska Cornhusker State Nevada Sagebrush State New Hampshire Granite State New Jersey Garden State New Mexico Land of Enchantment New York Empire State North Carolina Tar Heel State North Dakota Sioux State Ohio Buckeye State Oklahoma Sooner State Oregon Beaver State Pennsylvania Keystone State Rhode Island The Ocean State South Carolina Palmetto State South Dakota Mount Rushmore State Tennessee Volunteer State Texas Lone Star State Utah Beehive State Vermont Green Mountain State Virginia The Old Dominion Washington Evergreen State West Virginia Mountain State Wisconsin Badger State Wyoming Equality State ; run ;

%put _user_ ;

option error=0 ;

data _null_ ; input state: & $31. ; nickname = symget ('_' || translate (state, '_', ' ')) ; put state @ ; if not _error_ then put @20 nickname ; else put @23 '*BAD KEY!' ; _error_ = 0 ; cards ; abraca dabra Alabama tasmania Florida ukraine Georgia Indiana Maryland South Carolina south pole South Dakota Washington franklin West Virginia east virginia ; run ;

As to the advantages and disadvantages of this approach, I bet you have already realized what they are. Frankly, given the roster of other methods having no drawbacks of the above, I am having a difficult time envisaging circumstances under which it could be the method of choice. Job security, maybe... However, it is not completely devoid of interest. First, this is the only method except the newly-fangled V9 hash that allows for dynamic O(1) storage and search in the same data step, the macro memory serving as the repository. Secondly, the table is available without the need to reload it, to any subseqent process, capable of accessing the macro memory, in the same SAS session.

Kind regards, ================= Paul M. Dorfman Jacksonville, FL =================

>From: "Huang, Ya" <yhuang@AMYLIN.COM> >Reply-To: "Huang, Ya" <yhuang@AMYLIN.COM> >To: SAS-L@LISTSERV.UGA.EDU >Subject: Re: Ways to code (if Var contains the value of an Obs in another > SAS dataset). >Date: Tue, 26 Aug 2003 09:09:54 -0700 > >Paul, > >I'm not sure what you mean by "macro memory search", >can you give a sample code. Is this a new trick that >has never been revealed yet. > >Kind regards, > >Ya >-----Original Message----- >From: Paul Dorfman [mailto:paul_dorfman@HOTMAIL.COM] >Sent: Tuesday, August 26, 2003 8:43 AM >To: SAS-L@LISTSERV.UGA.EDU >Subject: Re: Ways to code (if Var contains the value of an Obs in >another SAS dataset). > > > >From: "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM> > > > >>"Haynes, Zac" <ZHaynes@BCBSM.COM> wrote in message > >>What are some efficient ways to compute whether a variable ($char80.) > >>contains the value of one of the observations of another SAS dataset? > > >Depends on the nature of the variables being looked up. If lookup is > >equality (col-n = v in table X is equal to col-m in table Y) than all >these > >can work well: > >array, hash, format, merge, SQL left join, SQL subquery lookup > >...bitmaps, conditional IN/OR/AND lists, SAS index lookup, INDEX() against >a >concatenated string, binary/interpolation search with POINT=..., macro >memory search, on... > >Kind regards, >================= >Paul M. Dorfman >Jacksonville, FL >================= > >_________________________________________________________________ >Get MSN 8 and help protect your children with advanced parental controls. >http://join.msn.com/?page=features/parental

_________________________________________________________________ Help protect your PC: Get a free online virus scan at McAfee.com. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


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