Date: Thu, 17 Apr 2008 21:15:37 -0500
Reply-To: sas 9 bi user <sas9bi@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: sas 9 bi user <sas9bi@GMAIL.COM>
Subject: Re: IS THIS LOOK-UP TABLE QUESTION?
In-Reply-To: <200804171329.m3HAkmbx001959@malibu.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1
Howard,
I am new to SAS and wanted to learn what HASH is, so that is why I asked
about HASH. I just read these postings and compile the code so as to learn
as much as possible (note I was not the orig poster). I know SQL well and
didnt know HASH and felt it would be good for my learning to ask how HASH
worked.
Thanks!
On 4/17/08, Howard Schreier <hs AT dc-sug DOT org> <
schreier.junk.mail@gmail.com> wrote:
>
> On Wed, 16 Apr 2008 21:38:31 -0500, sas 9 bi user <sas9bi@GMAIL.COM>
> wrote:
>
> >All, I am new at this and I dont really understand how HASH solution
> below
> >does what it does. I know SQL well
>
> Then why not do the entire job in a single SQL statement:
>
> create table foo2 as
> select *, myvar in (select myvar from mydata) as MyFlag
> from foo;
>
> >and can understand what is going on in
> >Arthur's PROC SQL solution but Toby's HASH method has me confused. Any
> >simple explanation on what this definekey, definedata, define done() are
> all
> >about? I can guess how it works but would rather some hand holding by
> you
> >noble mentors.
> >Thanks!
> >
> >
> >
> >On Wed, Apr 16, 2008 at 9:20 PM, toby dunn <tobydunn@hotmail.com> wrote:
> >
> >> Data Foo ;
> >> Input MyVar $5. ;
> >> Cards ;
> >> 11111
> >> 22222
> >> 12345
> >> 67890
> >> ;
> >> Run ;
> >>
> >>
> >> Data ManChew ;
> >> Input MyVar $5. ;
> >> Cards ;
> >> 12345
> >> 67890
> >> ;
> >> Run ;
> >>
> >>
> >>
> >> Data Need ;
> >>
> >> If _N_ = 1 Then Do ;
> >> Declare Hash HH( DataSet: 'ManChew' ) ;
> >> HH.DefineKey( 'MyVar' ) ;
> >> HH.DefineData( 'MyVar' ) ;
> >> HH.DefineDone();
> >> End ;
> >>
> >> Set Foo ;
> >>
> >> MyFlag = ( HH.Find() = 0 ) ;
> >>
> >> Run ;
> >>
> >>
> >>
> >>
> >> Toby Dunn
> >>
> >> "Don't bail. The best gold is at the bottom of barrels of crap."
> >> Randy Pausch
> >>
> >> "Be prepared. Luck is where preparation meets opportunity."
> >> Randy Pausch
> >>
> >>
> >> > Date: Wed, 16 Apr 2008 16:31:16 -0500
> >> > From: tw2@MAIL.COM
> >> > Subject: Re: IS THIS LOOK-UP TABLE QUESTION?
> >> > To: SAS-L@LISTSERV.UGA.EDU
> >> >
> >> > Thank you Arthur,
> >> >
> >> > Your code works as intended per my question.
> >> >
> >> > Since my actual question is a bit more complex, I will study your
> code
> >> and see if I can
> >> > modify it to fit my problem.
> >> >
> >> > If not, I will repost or reply with my actual data step question.
> >> >
> >> > T
> >> >
> >> > ----- Original Message -----
> >> > From: "Arthur Tabachneck"
> >> > To: SAS-L@LISTSERV.UGA.EDU, "Tom White"
> >> > Subject: Re: IS THIS LOOK-UP TABLE QUESTION?
> >> > Date: Wed, 16 Apr 2008 17:07:32 -0400
> >> >
> >> >
> >> > Tom,
> >> >
> >> > You could use proc sql to create the desired statement as a macro
> >> > variable. For example:
> >> >
> >> > data foo;
> >> > input myvar $5.;
> >> > cards;
> >> > 11111
> >> > 22222
> >> > 12345
> >> > 67890
> >> > ;
> >> >
> >> > data MYDATA;
> >> > input MyVar $5.;
> >> > cards;
> >> > 12345
> >> > 67890
> >> > ;
> >> >
> >> > proc sql noprint;
> >> > select "'"||MyVar||"'" into :MyVars
> >> > separated by ','
> >> > from MYDATA;
> >> > quit;
> >> >
> >> > data foo2;
> >> > set foo;
> >> > if MyVar in (&MyVars.) then MYFLAG=1; else MYFLAG=0;
> >> > run;
> >> >
> >> > HTH,
> >> > Art
> >> > ---------
> >> > On Wed, 16 Apr 2008 15:52:04 -0500, Tom White wrote:
> >> >
> >> >> Hell SAS-L,
> >> >>
> >> >> I have the following data step:
> >> >>
> >> >> data foo1;
> >> >> set foo;
> >> >> if MyVar in ('12345', '67890') then MYFLAG=1; else MYFLAG=0;
> >> >> run;
> >> >>
> >> >> Suppose I have a table called MYDATA(contains many hundreds):
> >> >> MyVar
> >> >> 12345
> >> >> 67890
> >> >>
> >> >> How can I rewrite the data step above to take advanatge of table
> MYDATA
> >> >> and avoid myself all this typing?
> >> >>
> >> >> Thnanks.
> >> >>
> >> >> T
> >> >>
> >> >>
> >> >>
> >> >> --
> >> >> Want an e-mail address like mine?
> >> >> Get a free e-mail account today at www.mail.com!
> >> >
> >> >
> >> > --
> >> > Want an e-mail address like mine?
> >> > Get a free e-mail account today at www.mail.com!
> >>
> >> _________________________________________________________________
> >> Pack up or back up�use SkyDrive to transfer files or keep extra
> copies.
> >> Learn how.
> >>
> >>
>
> http://www.windowslive.com/skydrive/overview.html?ocid=TXT_TAGLM_WL_Refresh_skydrive_packup_042008
> >>
>
|