<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Request for Efficent look up from one to many datasets? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229785#M41614</link>
    <description>&lt;P&gt;Here is a solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data one;&lt;BR /&gt;input ID_1$;&lt;BR /&gt;cards;&lt;BR /&gt;a&lt;BR /&gt;g&lt;BR /&gt;h&lt;BR /&gt;b&lt;BR /&gt;c&lt;BR /&gt;e&lt;BR /&gt;d&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;data two;&lt;BR /&gt;input ID_2$;&lt;BR /&gt;cards;&lt;BR /&gt;g&lt;BR /&gt;k&lt;BR /&gt;h&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;data three;&lt;BR /&gt;input ID_3$;&lt;BR /&gt;cards;&lt;BR /&gt;c&lt;BR /&gt;e&lt;BR /&gt;a&lt;BR /&gt;b&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;proc sort data=one;by id_1;&lt;BR /&gt;proc sort data=two;by id_2;&lt;BR /&gt;proc sort data=three;by id_3;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;merge one&amp;nbsp;&amp;nbsp; (in=a)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; two&amp;nbsp;&amp;nbsp; (in=b rename=(id_2=id_1))&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; three (in=c rename=(id_3=id_1));&lt;BR /&gt;by id_1;&lt;BR /&gt;if a;&lt;BR /&gt;if a and b then BiVal = 2;&lt;BR /&gt;if a and c then BiVal = 3;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Oct 2015 19:37:16 GMT</pubDate>
    <dc:creator>Steelers_In_DC</dc:creator>
    <dc:date>2015-10-13T19:37:16Z</dc:date>
    <item>
      <title>Request for Efficent look up from one to many datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229770#M41605</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a need to look up values from one dataset to many datasets and impute a binary value of 1 or 0 based on whether a match is found or not, For example, I have a dataset1:&lt;/P&gt;
&lt;P&gt;ID_1&lt;/P&gt;
&lt;P&gt;a&lt;/P&gt;
&lt;P&gt;g&lt;/P&gt;
&lt;P&gt;h&lt;/P&gt;
&lt;P&gt;b&lt;/P&gt;
&lt;P&gt;c&lt;/P&gt;
&lt;P&gt;e&lt;/P&gt;
&lt;P&gt;d&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dataset 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dataset3&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;ID_2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ID_3&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;g &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c&lt;/P&gt;
&lt;P&gt;k &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;e&lt;/P&gt;
&lt;P&gt;h &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; b&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wanted_output_dataset&lt;/P&gt;
&lt;P&gt;Dataset1 ID values should look up with dataset2 and if found the values should be imputed as 1 else 0.&lt;/P&gt;
&lt;P&gt;ID_1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ID_2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ID_3&lt;/P&gt;
&lt;P&gt;a &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;g &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;h &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;b &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;c &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;e &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;d &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;k &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please notice the values are values of g,k h of ID2 are found in ID_1, so being true should have value 1 and when not found 0 and the same logic applies for look up from ID_1 to ID_3 where C, E , A and B are found. Any help would be greatly appreciated. Thanks.&lt;/P&gt;
&lt;P&gt;Also note, Id1, Id2 and Id3 are datasets and not just variables, so the join/hash solution if anyone knows?&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Charlotte&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 18:39:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229770#M41605</guid>
      <dc:creator>CharlotteCain</dc:creator>
      <dc:date>2015-10-13T18:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: Request for Efficent look up from one to many datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229776#M41609</link>
      <description>&lt;P&gt;Easy and commonplace is to sort and merge.&amp;nbsp; After sorting:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; merge dataset1 (in=in1)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; dataset2 (in=in2 (rename=(id_2=id_1))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; dataset3 (in=in3 rename=(id_3=id_1));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by id_1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if in1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; id_2=in2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; id_3=in3;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But size of data sets and the need for speed may push in another direction.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 18:58:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229776#M41609</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-10-13T18:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: Request for Efficent look up from one to many datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229780#M41611</link>
      <description>&lt;P&gt;If you have a lot of lookups to do in the same DATA step then I would not recommend a hash join as there is too much coding required. I suggest you use a PROC FORMAT lookup.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Load your lookup datasets into PROC FORMAT using the CNTLIN option to create the lookup format then a single PUT function statement can do the lookup:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ID_2 = input(put(ID_1, $ID2_fmt.), 2.);&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 19:04:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229780#M41611</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2015-10-13T19:04:26Z</dc:date>
    </item>
    <item>
      <title>Re: Request for Efficent look up from one to many datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229783#M41613</link>
      <description>&lt;P&gt;proc sql;&lt;BR /&gt;select ID_1,case when ID_1=ID_2 then 1 else 0 end as ID_2,&lt;BR /&gt;case when ID_1=ID_3 then 1 else 0 end as ID_3&lt;BR /&gt;from id_1 left join id_2 on ID_1=ID_2&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; left join id_3 on ID_1=ID_3; &lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 19:19:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229783#M41613</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2015-10-13T19:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: Request for Efficent look up from one to many datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229785#M41614</link>
      <description>&lt;P&gt;Here is a solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data one;&lt;BR /&gt;input ID_1$;&lt;BR /&gt;cards;&lt;BR /&gt;a&lt;BR /&gt;g&lt;BR /&gt;h&lt;BR /&gt;b&lt;BR /&gt;c&lt;BR /&gt;e&lt;BR /&gt;d&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;data two;&lt;BR /&gt;input ID_2$;&lt;BR /&gt;cards;&lt;BR /&gt;g&lt;BR /&gt;k&lt;BR /&gt;h&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;data three;&lt;BR /&gt;input ID_3$;&lt;BR /&gt;cards;&lt;BR /&gt;c&lt;BR /&gt;e&lt;BR /&gt;a&lt;BR /&gt;b&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;proc sort data=one;by id_1;&lt;BR /&gt;proc sort data=two;by id_2;&lt;BR /&gt;proc sort data=three;by id_3;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;merge one&amp;nbsp;&amp;nbsp; (in=a)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; two&amp;nbsp;&amp;nbsp; (in=b rename=(id_2=id_1))&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; three (in=c rename=(id_3=id_1));&lt;BR /&gt;by id_1;&lt;BR /&gt;if a;&lt;BR /&gt;if a and b then BiVal = 2;&lt;BR /&gt;if a and c then BiVal = 3;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 19:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229785#M41614</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-10-13T19:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: Request for Efficent look up from one to many datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229791#M41615</link>
      <description>&lt;P&gt;Bob, You are a genius as always and I do like the logic with nice use of the automatic IN= variable. The dataset size is about a couple of million records &amp;nbsp;and in essence your solution should work fine. Please do not doubt my courtesy if I mark your solution as correct tomorrow coz It's already too late in England and I will sincerely thank once I run your solution at work. I hope is it should handle more datasets if need be, i mean instead of the example 3, if it has 7 or 8 for example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not the first time you have helped me out and so just thanks won't be enough. Thank you so much&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Charlotte&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also my sincere thanks to saskiwi, stat_sas, steeDC for your help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 19:51:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229791#M41615</guid>
      <dc:creator>CharlotteCain</dc:creator>
      <dc:date>2015-10-13T19:51:59Z</dc:date>
    </item>
    <item>
      <title>Re: Request for Efficent look up from one to many datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229797#M41616</link>
      <description>&lt;P&gt;I'm still not sure about the size of the data sets, and which one(s) might already be sorted.&amp;nbsp; But in any case, after sorting if necessary, switching from MERGE to SET will give you a significant improvement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set dataset2 (in=in2 rename=(id_2=id_1))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dataset3 (in=in3 rename=(id_3=id_1))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dataset1 (in=in1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by id_1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if first.id_1 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id_2=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id_3=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if in2 then id_2=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; else if in3 then id_3=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if in1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MERGE can be an absolute hog ... comparing its results with SET results might surprise you.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 19:56:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229797#M41616</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-10-13T19:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: Request for Efficent look up from one to many datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229799#M41617</link>
      <description>Add to that:  retain id_2 id_3;</description>
      <pubDate>Tue, 13 Oct 2015 20:01:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229799#M41617</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-10-13T20:01:07Z</dc:date>
    </item>
    <item>
      <title>Re: Request for Efficent look up from one to many datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229801#M41618</link>
      <description>&lt;P&gt;Noted, The concept of interleaving with SET and BY is something I will have to familiarise. Thank you so much once again Bob, I will try both and will reach out if I am stuck and need to follow up &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Enjoy your rest of the day,&lt;/P&gt;
&lt;P&gt;Charlotte&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 20:11:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229801#M41618</guid>
      <dc:creator>CharlotteCain</dc:creator>
      <dc:date>2015-10-13T20:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: Request for Efficent look up from one to many datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229802#M41619</link>
      <description>&lt;P&gt;Hi, another idea like the LOOKUP approach but not with formats (NOTE:&amp;nbsp; there is no value of K in your posted DATASET1, I added one to the data set) ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data x;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input id_1 :$1. @@;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;a g h b c e d k&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data y;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input y :$1. @@; &lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;g k h&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data z;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input z :$1. @@;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;c e a b&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data want;&lt;BR /&gt;length iny inz $10;&lt;BR /&gt;do until (lastz);&lt;BR /&gt;&amp;nbsp; set y z end=lastz;&lt;BR /&gt;&amp;nbsp; iny = catt(iny,y);&lt;BR /&gt;&amp;nbsp; inz = catt(inz,z);&lt;BR /&gt;end;&lt;BR /&gt;do until (lastx);&lt;BR /&gt;&amp;nbsp; set x end=lastx;&lt;BR /&gt;&amp;nbsp; id_2 = (findc(id_1,iny));&lt;BR /&gt;&amp;nbsp; id_3 = (findc(id_1,inz));&lt;BR /&gt;&amp;nbsp; output;&lt;BR /&gt;end;&lt;BR /&gt;keep id: ;&lt;BR /&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data set WANT ...&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp; id_1&amp;nbsp;&amp;nbsp;&amp;nbsp; id_2&amp;nbsp;&amp;nbsp;&amp;nbsp; id_3&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; g&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; d&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; k&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 20:22:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229802#M41619</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2015-10-13T20:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: Request for Efficent look up from one to many datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229804#M41620</link>
      <description>&lt;P&gt;Hi, another idea ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: &amp;nbsp;comments added on 10/14/15 after a request for more explanation of the posted code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;data x;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;input id_1 :$1. @@;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;datalines;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;a g h b c e d k&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* create an INDEX for data set Y;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* can be used to see if a given value of the INDEX variable ID_1;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* exists when the data set is read with SET Y/KEY=ID_1;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;data y (index=(id_1));&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;input id_1 :$1. @@; &lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;datalines;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;g k h&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* see comment for data set Y;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;data z (index=(id_1));&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;input id_1 :$1. @@;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;datalines;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;c e a b&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;data want;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* read a value of ID_1 from data set X;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;set x;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* use that value to find an observation in data set Y with the same valuye of ID_1;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;set y key=id_1/unique;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* if no value is found, the value of _ERROR_ is change to 1, if found _ERROR_ is 0;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* the ^_ERROR_ changes 1 to 0, 0 to 1 (now 1 represents found, 0 is not found;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;id_2 = ^_error_;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* reset the vlaue of _ERROR_ to 0;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* same process for lookup in data set Z;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;_error_ = 0;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;set z key=id_1/unique;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;id_3 = ^_error_;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;_error_ = 0;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;If data sets Y and Z already exist, without INDICES, you can add the INDEX to each with PROC DATASETS ...&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data y;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input id_1 :$1. @@; &lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;g k h&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data z;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input id_1 :$1. @@;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;c e a b&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;proc datasets lib=work noprint;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;modify y;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;index create id_1;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;modify z;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;index create id_1;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;PROC CONTENTS for data set Y (looks the same for Z) ...&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;Alphabetic List of Variables and Attributes&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;# Variable Type Len&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;1 &amp;nbsp; id_1 &amp;nbsp; Char &amp;nbsp;1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG style="line-height: normal; font-family: 'courier new', courier;"&gt;Alphabetic List of Indexes and Attributes&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # of&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;Unique&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;# &amp;nbsp; Index &amp;nbsp; Values&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;1&amp;nbsp; &amp;nbsp;&amp;nbsp;id_1 &amp;nbsp; &amp;nbsp; 3&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;ps &amp;nbsp;There's a LOT to know about using an INDEX, but for this example what you see above should suffice. &amp;nbsp;For more, consult the "king of the SAS index" ... Mike Raithel ...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;The Basics of Using SAS&amp;nbsp;Indexes&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;A href="http://www2.sas.com/proceedings/sugi30/247-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/247-30.pdf&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;The Complete Guide to SAS Indexes&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;A href="http://www.amazon.com/The-Complete-Guide-SAS-Indexes/dp/1590478495" target="_blank"&gt;http://www.amazon.com/The-Complete-Guide-SAS-Indexes/dp/1590478495&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2015 16:50:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229804#M41620</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2015-10-14T16:50:49Z</dc:date>
    </item>
    <item>
      <title>Re: Request for Efficent look up from one to many datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229805#M41621</link>
      <description>&lt;P&gt;Mike,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's workable as long as your data sets are small enough, and as long as your matching values containing a single character.&amp;nbsp; Once they contain multiple characters, you would be better off adding a delimiter that doesn't appear in the list.&amp;nbsp; So instead of creating:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;gkh&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#g#k#h#&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Adding the first and last delimiters makes searching easier later on.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 20:34:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229805#M41621</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-10-13T20:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Request for Efficent look up from one to many datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229807#M41622</link>
      <description>&lt;P&gt;Sure ... search for words rather than characters. The '#' is not in the list of default delimiters fof the FINDW function so a '|' is used in the CATX function to construct the lookup lists (INY, INZ). The TRIM function is used since the variable ID_1 has length of 10.&amp;nbsp; The ^^ that precedes the FINDW function changes the result from position of the string within the lookup list to a 0 or 1.&amp;nbsp; Var INY and INZ are given maximim length.&amp;nbsp; If 32K is too short then use the INDEX method posted earlier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: &amp;nbsp;COMMENTS added on 10/14/15 after a request for more explanation of the SAS code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#1 As has been mentioned, this method is good if the two "LOOKUP A VALUE OF ID_1" data sets (Y and Z) are not large. &amp;nbsp;The limit on large is a length of 32767 for either variable INY or INZ created with the CATX function&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#2 &amp;nbsp;If that's the case, use another method ... maybe the INDEX data set approach (though sorting might increase the speed of using the INDEX, neither data set X, Y, nor Z needs to be sorted as they do if MERGE is used to create variables ID_2 and ID_3).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#3 &amp;nbsp;Also, if an index is present in&amp;nbsp;all three data sets &amp;nbsp;(indices are ID_1 data set X, ID_2 data set Y, ID_3 data set Z), you can use the MERGE solution with sorting the data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data x;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input id_1 :$10. @@;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;aa gg hh bb cc ee dd kdlang&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data y;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input y :$10. @@; &lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;g kdlang h&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data z;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input z :$10. @@;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;cc ee aa bab&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;data want;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* specify a LENGTH for variables created with the CATX function;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* if there is no LENGTH specified and use of the CATX function;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* results in a variable with a length &amp;gt; 200;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* you will get a WARNING message in the SAS LOG (see below at end of post);&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;length iny inz $32767;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* use a loop to read observations in data sets Y and Z;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* create the new variables INY and INZ;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* after the loop, they look as follow;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;*&amp;nbsp;iny=g|kdlang|h&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* inz=cc|ee|aa|bab&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;do until (lastz);&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; set y z end=lastz;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; iny = catx('|',iny,y);&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; inz = catx('|',inz,z);&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;end;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* use the FINDW (find a WORD) function to see if a value of ID_1 in an observation in day set X;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* is present within variables either INY or INZ (shown above);&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* the FINDW function returns a ZERO if the value is NOT FOUND;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* it returns the position of ID1 in INY or INZ if the value is found;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;* the use of ^^ (not not) changes the value from the position to a 1 if any value is found;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;do until (lastx);&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; set x end=lastx;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; id_2 = ^^findw(iny,trim(id_1));&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; id_3 = ^^findw(inz,trim(id_1));&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; output;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;end;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;keep id: ;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data set WANT ...&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp; id_1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id_2&amp;nbsp;&amp;nbsp;&amp;nbsp; id_3&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; aa&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gg&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hh&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bb&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cc&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ee&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; kdlang&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;NOTE: &amp;nbsp;WARNING MESSAGE if too large (LENGTH &amp;gt; 200) a variable is created with any CAT function and no length has been specified earlier in the data step ...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;WARNING: In a call to the CATX function, the buffer allocated for the result was not&amp;nbsp;long enough to contain the concatenation of all the arguments&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2015 17:21:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229807#M41622</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2015-10-14T17:21:19Z</dc:date>
    </item>
    <item>
      <title>Re: Request for Efficent look up from one to many datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229934#M41650</link>
      <description>&lt;P&gt;Good evening &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;, Your solution worked beautifully. I still am happy with the merge solution. Like i said I will give you my feedback today after a nice day at work, I am so happy and thankful to you. You are a star!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13759"&gt;@MikeZdeb﻿&lt;/a&gt;&amp;nbsp;Thanks for the solution, I m in awe of all the responses. May i request you to please add some comments in your code if that's not a bother coz that would help me understand better.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Above all, thank you for the valuable time and the selfless help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Charlotte&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2015 16:26:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229934#M41650</guid>
      <dc:creator>CharlotteCain</dc:creator>
      <dc:date>2015-10-14T16:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: Request for Efficent look up from one to many datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229963#M41654</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13759"&gt;@MikeZdeb﻿&lt;/a&gt;&amp;nbsp;Thank you so much Sir! for adding the comments. I really really appreciate. Sorry for the bother. Have a great day!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2015 18:59:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Request-for-Efficent-look-up-from-one-to-many-datasets/m-p/229963#M41654</guid>
      <dc:creator>CharlotteCain</dc:creator>
      <dc:date>2015-10-14T18:59:33Z</dc:date>
    </item>
  </channel>
</rss>

