From: Ram on 23 Apr 2010 13:02 Hello, I am a relatively new user of Hash Objects. I am able to use hashes to do simple merges with duplicates. How ever, I want to replicate following merge step using hash objects: data match firstonly secondonly; merge first(in=first) second(in=second); by commonkey; if first and second then output match; if first and not second then output firstonly; if not first and second then output secondonly; run; Any suggestions on how to implement this? ~Ram
From: Patrick on 23 Apr 2010 19:13 Hi Ram Let's assume: - FIRST is your base table and SECOND is your lookup (hash) table. - The keys in the lookup table are unique - you're using a syntax like: rc=h.find(). "if first and second then output match;" Check the value of rc and output if lookup found something if first and not second then output firstonly; Check the value of rc and output if lookup found nothing something "if not first and second then output secondonly;" That's a hard one. There is no record in the base table so no lookup will happen at all and you will never encounter this case. It might be possible to construct some workaround using the ITER object but: My gut feeling is that this is just a case where using a merge with first and last is a better approach. HTH Patrick
From: Ram on 26 Apr 2010 10:46 On Apr 23, 4:13 pm, Patrick <patrick.mat...(a)gmx.ch> wrote: > Hi Ram > > Let's assume: > - FIRST is your base table and SECOND is your lookup (hash) table. > - The keys in the lookup table are unique > - you're using a syntax like: rc=h.find(). > > "if first and second then output match;" > Check the value of rc and output if lookup found something > > if first and not second then output firstonly; > Check the value of rc and output if lookup found nothing something > > "if not first and second then output secondonly;" > That's a hard one. There is no record in the base table so no lookup > will happen at all and you will never encounter this case. > It might be possible to construct some workaround using the ITER > object but: My gut feeling is that this is just a case where using a > merge with first and last is a better approach. > > HTH > Patrick Thanks Patrick for your response....I started implementing using merge technique for my current project. After using hash tables to replace some of my merge processes and even to replace some proc freq processes, I feel guilty to use this merge technique again. ~Ram
From: Richard A. DeVenezia on 27 Apr 2010 13:57 On Apr 23, 1:02 pm, Ram <janakiram.madipi...(a)earlywarning.com> wrote: > Hello, > > I am a relatively new user of Hash Objects. I am able to use hashes to > do simple merges with duplicates. How ever, I want to replicate > following merge step using hash objects: > > data match firstonly secondonly; > merge first(in=first) > second(in=second); > by commonkey; > if first and second then output match; > if first and not second then output firstonly; > if not first and second then output secondonly; > run; > > Any suggestions on how to implement this? > > ~Ram What you may consider to be a merge may only be a lookup with satellite variable assignment. What are the data conditions that lead you to using Hash for merging ? There is probably little reason to re-invent the MERGE wheel. You should always be sure to understand what happens when the log shows NOTE: MERGE statement has more than one data set with repeats of BY values. -- Richard A. DeVenezia http://www.devenezia.com
From: Ram on 27 Apr 2010 19:28 On Apr 27, 10:57 am, "Richard A. DeVenezia" <rdevene...(a)gmail.com> wrote: > On Apr 23, 1:02 pm, Ram <janakiram.madipi...(a)earlywarning.com> wrote: > > > > > > > Hello, > > > I am a relatively new user of Hash Objects. I am able to use hashes to > > do simple merges with duplicates. How ever, I want to replicate > > following merge step using hash objects: > > > data match firstonly secondonly; > > merge first(in=first) > > second(in=second); > > by commonkey; > > if first and second then output match; > > if first and not second then output firstonly; > > if not first and second then output secondonly; > > run; > > > Any suggestions on how to implement this? > > > ~Ram > > What you may consider to be a merge may only be a lookup with > satellite variable assignment. > > What are the data conditions that lead you to using Hash for merging ? > > There is probably little reason to re-invent the MERGE wheel. > You should always be sure to understand what happens when the log > shows > NOTE: MERGE statement has more than one data set with repeats of BY > values. > > -- > Richard A. DeVeneziahttp://www.devenezia.com- Hide quoted text - > > - Show quoted text - Actually merge technique is just fine in this case. I am trying to implement my merge process using hashes to shorten the run time. ~Ram
|
Pages: 1 Prev: PROC MIXED, panel data and fixed effects Next: Siebel Business Analyst -- MI |