<?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: how to find the value I am looking for from my dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/228353#M41247</link>
    <description>&lt;P&gt;Hi.&amp;nbsp; You can search a numeric array with the WHICHN function (no loop needed ... there's a WHICHC for character data).&amp;nbsp; To look for one value ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* note NUMERIC emplid;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data have1;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input emplid @@;&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;1111 2222 3333&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 have2;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input mgrid_1-mgrid_5;&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;101 1111 1212 2124 14322&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;201 2211 2222 3434 5656&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;301 3322 2124 5434 3333&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;401 3355 1199 55 77&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;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data want (keep=emplid mgrid);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;retain emplid 1111;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;array grid(*) mgrid_1-mgrid_5;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set have2;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;found = whichn(emplid, of grid(*));&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;if found then do; mgrid=grid(found-1); output; end;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to search for more than one EMPLID ...&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data want (keep=emplid mgrid);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* lookup array (HAVE1) ... places all values in an array;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;array lookup(3) _temporary_&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;do j=1 to howmany;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; set have1 nobs=howmany;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; lookup(j) = emplid;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* check grid (HAVE2) for values in lookup (HAVE1);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;array grid(5) mgrid_1-mgrid_5;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;do until (last);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; set have2 end=last;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;do j=1 to howmany;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; found = whichn(lookup(j), of grid(*));&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; if found then do; emplid=lookup(j); mgrid=grid(found-1); output; end;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data set WANT ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp; emplid&amp;nbsp;&amp;nbsp;&amp;nbsp; mgrid&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; 1111&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 101&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; 2222&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2211&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; 3333&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5434&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 04 Oct 2015 19:08:47 GMT</pubDate>
    <dc:creator>MikeZdeb</dc:creator>
    <dc:date>2015-10-04T19:08:47Z</dc:date>
    <item>
      <title>how to find the value I am looking for from my dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/227914#M41111</link>
      <description>I have a small dataset with values like: emplid 1111 2222 3333 Another bigger dataset like: mgrid_1 mgrid_2 mgrid_3 mgrid_4...mgrid_11 101 1111 121212 202 23232 2222 34321 202 1111 23432 3333 11212 4444 55555 6666 Basically, the value of emlid = 1111,2222,3333 locate in different columns of my bigger dataset. The result I am looking for would be emplid mgrid 1111 101 2222 23232 3333 23432. Could anybody help me with a simple solution? Thanks a lot!</description>
      <pubDate>Wed, 30 Sep 2015 19:53:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/227914#M41111</guid>
      <dc:creator>EEEY</dc:creator>
      <dc:date>2015-09-30T19:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the value I am looking for from my dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/227917#M41112</link>
      <description>&lt;P&gt;I have no idea what you are trying to say.&amp;nbsp; Put in a format like below so we can see what your actual datasets look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have1;&lt;BR /&gt;input emplid$;&lt;BR /&gt;cards;&lt;BR /&gt;1111&lt;BR /&gt;2222&lt;BR /&gt;3333&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;data have2;&lt;BR /&gt;input mgrid_1 mgrid2 mgrid3;&lt;BR /&gt;cards;&lt;BR /&gt;1111 2222 3333&lt;BR /&gt;;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2015 20:04:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/227917#M41112</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-09-30T20:04:25Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the value I am looking for from my dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/227918#M41113</link>
      <description>also a dataset that you 'want'.</description>
      <pubDate>Wed, 30 Sep 2015 20:04:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/227918#M41113</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-09-30T20:04:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the value I am looking for from my dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/227919#M41114</link>
      <description>&lt;P&gt;I think you'd need to use an ARRAY that loops over all possible columns where the emplid might be. This also allows you to determine the value in the column preceding this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array x{i} col1-col999;
do i=2 to 999;    /* Note 1111 cannot be in col1 */
    if x{i}=1111 then do; emplid=x{i}; mgrid=x{i-1}; output; end;
end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2015 20:06:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/227919#M41114</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-09-30T20:06:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the value I am looking for from my dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/227921#M41115</link>
      <description>data have1;&lt;BR /&gt;input emplid$;&lt;BR /&gt;cards;&lt;BR /&gt;1111&lt;BR /&gt;2222&lt;BR /&gt;3333&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;data have2;&lt;BR /&gt;input mgrid_1 mgrid_2 mgrid_3 mgrid_4 mgrid_5;&lt;BR /&gt;cards;&lt;BR /&gt;101 1111 1212 2124 14322&lt;BR /&gt;201 2211 2222 3434 5656&lt;BR /&gt;301 3322 2124 5434 3333&lt;BR /&gt;401 3355 1199 55 77&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;input emplid mgrid;&lt;BR /&gt;cards;&lt;BR /&gt;1111 101&lt;BR /&gt;2222 2211&lt;BR /&gt;3333 5434&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;My dataset would be like this. The last dataset is what I am looking for</description>
      <pubDate>Wed, 30 Sep 2015 20:14:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/227921#M41115</guid>
      <dc:creator>EEEY</dc:creator>
      <dc:date>2015-09-30T20:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the value I am looking for from my dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/227922#M41116</link>
      <description>Thanks PaigeMiller. I guess that would be the solution but I am really bad at array. I have posted the code for the datasets I have and I want. the value 1111 is in my dataset have1.. how should i modify your program?</description>
      <pubDate>Wed, 30 Sep 2015 20:17:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/227922#M41116</guid>
      <dc:creator>EEEY</dc:creator>
      <dc:date>2015-09-30T20:17:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the value I am looking for from my dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/227925#M41118</link>
      <description>&lt;P&gt;Well, to tell you the truth, I'd like to see you learn a little about arrays instead of me doing the work for you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe you ought to be able to give it a try to get my code to work on your exact data. If it doesn't work, show us the code and the SASLOG and we'll figure out how to make progress.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2015 20:31:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/227925#M41118</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-09-30T20:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the value I am looking for from my dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/227929#M41119</link>
      <description>&lt;P&gt;I am also not too familiar with arrays.&amp;nbsp; I need to get on that.&amp;nbsp; Here is a solution using the same mindset but taking advantage of transpose:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have1;&lt;BR /&gt;input emplid$;&lt;BR /&gt;cards;&lt;BR /&gt;1111&lt;BR /&gt;2222&lt;BR /&gt;3333&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;data have2;&lt;BR /&gt;input mgrid_1$ mgrid_2$ mgrid_3$ mgrid_4$ mgrid_5$;&lt;BR /&gt;cards;&lt;BR /&gt;101 1111 1212 2124 14322&lt;BR /&gt;201 2211 2222 3434 5656&lt;BR /&gt;301 3322 2124 5434 3333&lt;BR /&gt;401 3355 1199 55 77&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;proc transpose data=have2 out=tran2;by mgrid_1;var mgrid_2 mgrid_3 mgrid_4 mgrid_5;&lt;BR /&gt;&lt;BR /&gt;data lag;&lt;BR /&gt;set tran2;&lt;BR /&gt;by mgrid_1;&lt;BR /&gt;mgrid = lag(col1);&lt;BR /&gt;if first.mgrid_1 then mgrid = mgrid_1;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select a.emplid,b.mgrid&lt;BR /&gt;from have1 a left join&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lag b on&lt;BR /&gt;a.emplid = b.col1;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2015 20:37:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/227929#M41119</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-09-30T20:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the value I am looking for from my dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/228338#M41242</link>
      <description>&lt;P&gt;Thanks PaigeMiller for your response. Actually your code is working well. But the thing is 1111 is just one value in the data set Have1. In my really data set Have1, I have 200+ rows. How to modify your code.&lt;BR /&gt;&lt;BR /&gt;The code I have :&lt;BR /&gt;&lt;BR /&gt;data have1;&lt;BR /&gt;set emp_level_final2;&lt;BR /&gt;keep mgrid_1-mgrid_11;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data have2;&lt;BR /&gt;set MS_MGR;&lt;BR /&gt;keep emplid;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have1;&lt;BR /&gt;array x{11} mgrid_1-mgrid_11;&lt;BR /&gt;&lt;BR /&gt;set have2;&lt;BR /&gt;array y{1} emplid;&lt;BR /&gt;;&lt;BR /&gt;do i=2 to 11;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Note 1111 cannot be in col1 */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if x{i}=y{1}&amp;nbsp; then do; emplid=y{1};sup_id=x{i-1}; output; end;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;By using the code above, it only gave me 1 row in the Want data set that I knew it should have come back with about 100 rows). There was no errors in the log. Please help!&lt;/P&gt;</description>
      <pubDate>Sun, 04 Oct 2015 01:26:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/228338#M41242</guid>
      <dc:creator>EEEY</dc:creator>
      <dc:date>2015-10-04T01:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the value I am looking for from my dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/228339#M41243</link>
      <description>&lt;P&gt;Thanks for your response. Your code is working well. But my dataset Have2 has 182K rows of record and 11 columns.&lt;/P&gt;&lt;P&gt;I am not sure if proc transpose is a good idea.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Oct 2015 01:27:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/228339#M41243</guid>
      <dc:creator>EEEY</dc:creator>
      <dc:date>2015-10-04T01:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the value I am looking for from my dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/228353#M41247</link>
      <description>&lt;P&gt;Hi.&amp;nbsp; You can search a numeric array with the WHICHN function (no loop needed ... there's a WHICHC for character data).&amp;nbsp; To look for one value ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* note NUMERIC emplid;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data have1;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input emplid @@;&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;1111 2222 3333&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 have2;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input mgrid_1-mgrid_5;&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;101 1111 1212 2124 14322&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;201 2211 2222 3434 5656&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;301 3322 2124 5434 3333&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;401 3355 1199 55 77&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;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data want (keep=emplid mgrid);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;retain emplid 1111;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;array grid(*) mgrid_1-mgrid_5;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set have2;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;found = whichn(emplid, of grid(*));&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;if found then do; mgrid=grid(found-1); output; end;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to search for more than one EMPLID ...&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data want (keep=emplid mgrid);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* lookup array (HAVE1) ... places all values in an array;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;array lookup(3) _temporary_&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;do j=1 to howmany;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; set have1 nobs=howmany;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; lookup(j) = emplid;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* check grid (HAVE2) for values in lookup (HAVE1);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;array grid(5) mgrid_1-mgrid_5;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;do until (last);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; set have2 end=last;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;do j=1 to howmany;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; found = whichn(lookup(j), of grid(*));&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; if found then do; emplid=lookup(j); mgrid=grid(found-1); output; end;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data set WANT ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp; emplid&amp;nbsp;&amp;nbsp;&amp;nbsp; mgrid&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; 1111&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 101&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; 2222&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2211&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; 3333&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5434&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Oct 2015 19:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/228353#M41247</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2015-10-04T19:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the value I am looking for from my dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/228572#M41294</link>
      <description>&lt;P&gt;May be I missunderstand your data and how it's structured. It appears&amp;nbsp;the same value in "have2" can exist more than once. Below code will return at least one row per source row from have1 - but return multiple rows if empid matches more than once to a value in have2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In below code "&amp;amp;colon;" needs to be replaced with "&lt;STRONG&gt;:&lt;/STRONG&gt;"&lt;/P&gt;&lt;P&gt;&lt;IMG title="Capture.PNG" alt="Capture.PNG" src="https://communities.sas.com/t5/image/serverpage/image-id/425iD229D5F2782FD06F/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
  input empid;
cards;
1111
2222
3333
2124
9999
;

data have2;
  input mgrid_1 mgrid_2 mgrid_3 mgrid_4 mgrid_5;
cards;
101 1111 1212 2124 14322
201 2211 2222 3434 5656
301 3322 2124 5434 3333
401 3355 1199 55 77
;

data want(keep=empid mgrid);
  if _n_=1 then
    do;
      if 0 then set have1(keep=empid) have2(keep=mgrid_1 rename=(mgrid_1=mgrid));
      dcl hash h1(multidata&amp;amp;colon;'y');
      h1.defineKey('empid');
      h1.defineData('mgrid');
      h1.defineDone();

      array mgrids {*} mgrid_1 - mgrid_5;
      do while(not last);
        set have2 end=last;
        do i=2 to dim(mgrids);
          h1.add(key:mgrids[i], data&amp;amp;colon;mgrids[i-1]);
        end;
      end;
    end;
    call missing(of _all_);

    set have1;
    _rc=h1.find();
    output;
    do while(h1.find_next() = 0);
      output;
    end;
 run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2015 06:13:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/228572#M41294</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-10-08T06:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the value I am looking for from my dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/229053#M41413</link>
      <description>&lt;P&gt;Thanks Mike for your solution. Unfortunately emplid and mgrid in my 2 datasets are both character instead of numeric. I am wondering if I still can use with whichn function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code is :&lt;/P&gt;&lt;P&gt;data&amp;nbsp;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;want (&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;keep&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;=emplid mgrid);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;* lookup array (HAVE1) ... places all values in an array;&lt;/P&gt;&lt;P&gt;array&amp;nbsp;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;lookup(*) $ &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;_temporary_&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;do&amp;nbsp;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;j=&lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;to&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt; howmany;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;set&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt; have1 &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;nobs&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;=howmany;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;lookup(j) = emplid;&lt;/P&gt;&lt;P&gt;end&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;* check grid (HAVE2) for values in lookup (HAVE1);&lt;/P&gt;&lt;P&gt;array&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;g&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;rid(&lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;11&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;) $ mgrid_1-mgrid_11;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;do&amp;nbsp;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;until&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt; (last);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;set&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt; have2 &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;end&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;=last;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;do&amp;nbsp;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;j=&lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;to&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;267&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;found = whichn(lookup(j), of grid(*));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;if&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt; found &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;then&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;do&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;; emplid=lookup(j); mgrid=grid(found-&lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;); &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;output&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;end&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;end&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;end&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;run&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;The log I got is:&lt;/P&gt;&lt;P&gt;24 data want (keep=emplid mgrid);&lt;/P&gt;&lt;P&gt;25 * lookup array (HAVE1) ... places all values in an array;&lt;/P&gt;&lt;P&gt;26 array lookup(*) $ _temporary_;&lt;/P&gt;&lt;P&gt;ERROR: The non-variable based array lookup has been defined with zero elements.&lt;/P&gt;&lt;P&gt;27 do j=1 to howmany;&lt;/P&gt;&lt;P&gt;28 set have1 nobs=howmany;&lt;/P&gt;&lt;P&gt;29 lookup(j) = emplid;&lt;/P&gt;&lt;P&gt;ERROR: Too many array subscripts specified for array lookup.&lt;/P&gt;&lt;P&gt;30 end;&lt;/P&gt;&lt;P&gt;31&lt;/P&gt;&lt;P&gt;32 * check grid (HAVE2) for values in lookup (HAVE1);&lt;/P&gt;&lt;P&gt;33 array grid(11) $ mgrid_1-mgrid_11;&lt;/P&gt;&lt;P&gt;34 do until (last);&lt;/P&gt;&lt;P&gt;35 set have2 end=last;&lt;/P&gt;&lt;P&gt;36 do j=1 to 267;&lt;/P&gt;&lt;P&gt;37 found = whichn(lookup(j), of grid(*));&lt;/P&gt;&lt;P&gt;ERROR: Too many array subscripts specified for array lookup.&lt;/P&gt;&lt;P&gt;38 if found then do; emplid=lookup(j); mgrid=grid(found-1); output; end;&lt;/P&gt;&lt;P&gt;ERROR: Too many array subscripts specified for array lookup.&lt;/P&gt;&lt;P&gt;39 end;&lt;/P&gt;&lt;P&gt;40 end;&lt;/P&gt;&lt;P&gt;41 run;&lt;/P&gt;&lt;P&gt;NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).&lt;/P&gt;&lt;P&gt;37:19 37:33&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;&lt;P&gt;WARNING: The data set WORK.WANT may be incomplete. When this step was stopped there were 0 observations and 2 variables.&lt;/P&gt;&lt;P&gt;WARNING: Data set WORK.WANT was not replaced because this step was stopped.&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.00 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.01 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2015 04:37:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/229053#M41413</guid>
      <dc:creator>EEEY</dc:creator>
      <dc:date>2015-10-08T04:37:26Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the value I am looking for from my dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/229054#M41414</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for this cool hash object solution. I learned before (a bit only) and felt it was not really useful but right now I&amp;nbsp;realized that this is hash oject should be used for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only thing was that I had to remove (keep=emplid mgrid) to get the complete dataset and then did the seperate data step to keep these two columns only. Otherwise it only gave me one column mgrid.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Really appreciate.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2015 04:41:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/229054#M41414</guid>
      <dc:creator>EEEY</dc:creator>
      <dc:date>2015-10-08T04:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the value I am looking for from my dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/230015#M41675</link>
      <description>&lt;P&gt;&amp;nbsp;hI Patrick,&lt;BR /&gt;&lt;BR /&gt;I am sure you are the expert of hash object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually my dataset Have2 is even more complicated than I think.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So my&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; have1&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; empid&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;cards&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt;1111
2222
3333
2124
9999&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;

&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; have2&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
  &lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; mgrid_1 mgrid_2 mgrid_3 mgrid_4 mgrid_5&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;cards&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt;101 1111 1212 2124 14322
201 2211 2222 3434 5656
301 3322 2124 5434 3333
401 3355 1199 55 77&lt;BR /&gt;234 2222 2323 2121 55&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;&lt;BR /&gt;So I have added the last row into the dataset have2.&lt;BR /&gt;&lt;BR /&gt;When this look-up process execute, note that value 2222 appeares at two spot in the dataset have2. &lt;BR /&gt;One in column mgrid_2  and the other one in column mgrid_3.&lt;BR /&gt;&lt;BR /&gt;The result I want to see would be like:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;emplid mgrid col&lt;BR /&gt;1111   101   1
2222   2211  2&lt;BR /&gt;2222   234   1
3333   5434  4 
2124   3322  2&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;&amp;nbsp;The Column col I would like to add into the want dataset is the level of the manager from Have2 dataset.&lt;BR /&gt;&lt;BR /&gt;Hope you could help me out again.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Thanks a lot.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 06:19:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/230015#M41675</guid>
      <dc:creator>EEEY</dc:creator>
      <dc:date>2015-10-15T06:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the value I am looking for from my dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/230016#M41676</link>
      <description>&lt;P&gt;My post got messy up. I repost it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;hI Patrick,&lt;BR /&gt;&lt;BR /&gt;I am sure you are the expert of hash object. Actually my dataset Have2 is even more complicated than I think.&lt;BR /&gt;So my datasets are:&lt;BR /&gt;&lt;BR /&gt;data have1;&lt;BR /&gt;input empid;&lt;BR /&gt;cards;1111&lt;BR /&gt;2222&lt;BR /&gt;3333&lt;BR /&gt;2124&lt;BR /&gt;9999;&lt;BR /&gt;&lt;BR /&gt;data have2;&lt;BR /&gt;&amp;nbsp; input mgrid_1 mgrid_2 mgrid_3 mgrid_4 mgrid_5;&lt;BR /&gt;cards;&lt;BR /&gt;101 1111 1212 2124 14322&lt;BR /&gt;201 2211 2222 3434 5656&lt;BR /&gt;301 3322 2124 5434 3333&lt;BR /&gt;401 3355 1199 55 77&lt;BR /&gt;234 2222 2323 2121 55;&lt;BR /&gt;&lt;BR /&gt;I have added the last row into the dataset have2 to show the complexity of my dataset. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;When this look-up process executes, note that value 2222 appeares at two spots in the dataset have2.&lt;BR /&gt;One in column mgrid_2&amp;nbsp; and the other one in column mgrid_3.The result I want to see would be like:&lt;BR /&gt;&lt;BR /&gt;emplid mgrid col&lt;BR /&gt;1111&amp;nbsp;&amp;nbsp; 101&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;2222&amp;nbsp;&amp;nbsp; 2211&amp;nbsp; 2&lt;BR /&gt;2222&amp;nbsp;&amp;nbsp; 234&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;3333&amp;nbsp;&amp;nbsp; 5434&amp;nbsp; 4&lt;BR /&gt;2124&amp;nbsp;&amp;nbsp; 3322&amp;nbsp; 2&lt;BR /&gt;&lt;BR /&gt;The Column col I would like to add into the want dataset is the level of the manager from Have2 dataset.Hope you could help me out again.&lt;BR /&gt;&lt;BR /&gt;Thanks a lot.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2015 06:28:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-value-I-am-looking-for-from-my-dataset/m-p/230016#M41676</guid>
      <dc:creator>EEEY</dc:creator>
      <dc:date>2015-10-15T06:28:22Z</dc:date>
    </item>
  </channel>
</rss>

