<?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: selecting only one match per record in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335932#M76114</link>
    <description>&lt;P&gt;Mark,&lt;/P&gt;
&lt;P&gt;No . that would not happen. if that happened, OP must have replicated record in large table. That is another story.&lt;/P&gt;</description>
    <pubDate>Sun, 26 Feb 2017 02:07:33 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2017-02-26T02:07:33Z</dc:date>
    <item>
      <title>selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335558#M75969</link>
      <description>&lt;P&gt;Hi there, I am trying to find a more efficient way to produce a smallish matched control group from a very very very large data set. So what I want is for sas to read 1 record, then find 1 match and then move back to read the next. So say the two data sets look like&lt;/P&gt;&lt;P&gt;Data set1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;informat gender $1. ethnicity $1.;&lt;/P&gt;&lt;P&gt;input serial gender ethnicity wage;&lt;/P&gt;&lt;P&gt;&amp;nbsp;datalines;&lt;/P&gt;&lt;P&gt;&amp;nbsp; 232 M W 230&lt;/P&gt;&lt;P&gt;&amp;nbsp; 233 F B 240&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data set2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;informat gender $1. ethnicity $1.;&lt;/P&gt;&lt;P&gt;input id gender ethnicity wage;&lt;/P&gt;&lt;P&gt;1 M W 254&lt;/P&gt;&lt;P&gt;2 M W 270&lt;/P&gt;&lt;P&gt;3.M B 255&lt;/P&gt;&lt;P&gt;4 M W 230&lt;/P&gt;&lt;P&gt;5 F B 211&lt;/P&gt;&lt;P&gt;6 F B 222&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the output would be simply&lt;/P&gt;&lt;P&gt;1 M W 254&lt;/P&gt;&lt;P&gt;5 F B 240&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought about match them first and then trim it down (removing duplicate a.serial). But given the size of the dataset it takes an awfully long time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;proc sql;&lt;BR /&gt;&amp;nbsp;create table control as&lt;BR /&gt;&amp;nbsp;&amp;nbsp; select a.serial b.*&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from set1 a, set2 b&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where a.gender = b.gender And a.ethnicity = b.ethnicity AND a.wage*0.9&amp;lt;=b.wage&amp;lt;=a.wage*1.2&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by id;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas? Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 11:00:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335558#M75969</guid>
      <dc:creator>torestin</dc:creator>
      <dc:date>2017-02-24T11:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335560#M75970</link>
      <description>&lt;P&gt;You can try next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
 create table control as
   select a.serial b.*
       from set1 a
       left join set2 b
       on a.gender = b.gender And 
            a.ethnicity = b.ethnicity AND 
            a.wage*0.9&amp;lt;=b.wage&amp;lt;=a.wage*1.2
      order by id;  
 quit;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 11:20:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335560#M75970</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-24T11:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335561#M75971</link>
      <description>&lt;P&gt;What about&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data set1;
informat gender $1. ethnicity $1.;
input serial gender ethnicity wage;
datalines;
232 M W 230
233 F B 240
;
run;

data set2;
informat gender $1. ethnicity $1.;
input id gender ethnicity wage;
cards;
1 M W 254
2 M W 270
3 M B 255
4 M W 230
5 F B 211
6 F B 222
;
run;

proc sort data=set1;
by gender ethnicity;
run;

proc sort data=set2;
by gender ethnicity;
run;

data want;
merge
  set1 (in=a keep=gender ethnicity wage rename=(wage=wage_a))
  set2 (in=b)
;
by gender ethnicity;
retain flag;
if first.ethnicity then flag = 1;
if flag
then do;
  if 0.9 * wage_a &amp;lt;= wage &amp;lt;= 1.2 * wage_a
  then do;
    flag = 0;
    output;
  end;
end;
drop flag wage_a;
run;

proc print data=want noobs;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result is&lt;/P&gt;
&lt;PRE&gt;gender    ethnicity    id    wage

  F           B         6     222
  M           W         1     254
&lt;/PRE&gt;
&lt;P&gt;(your expected result value of 240 for wage seems to be a typo, as that value only appears in set1)&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 11:27:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335561#M75971</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-24T11:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335563#M75972</link>
      <description>mmm that still returns two matches for the first line M W in a&lt;BR /&gt;&lt;BR /&gt;M W 254&lt;BR /&gt;&lt;BR /&gt;M W 270&lt;BR /&gt;&lt;BR /&gt;F B 234&lt;BR /&gt;&lt;BR /&gt;where as I want it to do&lt;BR /&gt;&lt;BR /&gt;M W 254&lt;BR /&gt;&lt;BR /&gt;F B 234&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Fri, 24 Feb 2017 11:31:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335563#M75972</guid>
      <dc:creator>torestin</dc:creator>
      <dc:date>2017-02-24T11:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335570#M75974</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/130809"&gt;@torestin&lt;/a&gt; wrote:&lt;BR /&gt;mmm that still returns two matches for the first line M W in a&lt;BR /&gt;&lt;BR /&gt;M W 254&lt;BR /&gt;&lt;BR /&gt;M W 270&lt;BR /&gt;&lt;BR /&gt;F B 234&lt;BR /&gt;&lt;BR /&gt;where as I want it to do&lt;BR /&gt;&lt;BR /&gt;M W 254&lt;BR /&gt;&lt;BR /&gt;F B 234&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Which of the suggested codes do you mean? My result is included in my post and has only two results.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 13:07:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335570#M75974</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-24T13:07:12Z</dc:date>
    </item>
    <item>
      <title>Re: selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335780#M76038</link>
      <description>&lt;P&gt;Hey thanks for that. Sorry I should have been more clearer. What I actually want is for the output to have the same observations with set1 and for each record in set 1 to be matched only once (even if they have multiple matches in set2 on the same criteria). So I changed that to first.id. The first.ethnicity didn't work if I have three lines in set 1 like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;232 M W 230&lt;/P&gt;&lt;P&gt;233 F B 240&lt;/P&gt;&lt;P&gt;234 M W 254&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;etc. as it seems to discard the last record and still returns 2 matches. I tried use first.id (from set2), still doesn't work. Ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 22:02:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335780#M76038</guid>
      <dc:creator>torestin</dc:creator>
      <dc:date>2017-02-24T22:02:29Z</dc:date>
    </item>
    <item>
      <title>Re: selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335788#M76039</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/130809"&gt;@torestin&lt;/a&gt;&amp;nbsp;Would code like below do the job for you?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data sample_set;
  informat gender $1. ethnicity $1.;
  input serial gender ethnicity wage;
  datalines;
232 M W 230
233 F B 240
;
run;

data huge_set;
  informat gender $1. ethnicity $1.;
  input id gender ethnicity wage;
  cards;
1 M W 254
2 M W 270
3 M B 255
4 M W 230
5 F B 211
6 F B 222
;
run;

data want(drop=sample_wage);

  set huge_set;

  if _n_=1 then
    do;
      if 0 then set sample_set(rename=(wage=sample_wage));
      dcl hash h1(dataset:'sample_set(rename=(wage=sample_wage))');
      h1.defineKey('gender','ethnicity');
      h1.defineData('serial','sample_wage');
      h1.defineDone();
    end;

  if h1.find()=0 then
    do;
      if wage*0.9&amp;lt;=sample_wage&amp;lt;=wage*1.2 then  
        do;
          output;
          h1.remove();
          if h1.num_items=0 then stop;
        end;
    end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code amended as suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2017 17:55:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335788#M76039</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-02-26T17:55:14Z</dc:date>
    </item>
    <item>
      <title>Re: selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335794#M76041</link>
      <description>&lt;P&gt;Folks:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I like &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;'s&amp;nbsp;solution, but it depends on the OP's small data set having only 1 obs per ethnicity /gender.&amp;nbsp; Otherwise, the hash object will have to be modified, as well as its processing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, if large is not randomly ordered with regards to (1) wage and (2) any other vars pertinent to the subsequent analysis, then none of the responses offered so far produce both (1) a single&amp;nbsp;matching large obs per small obs, and (2) unbiased sampling from large.&amp;nbsp; So my question to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/130809"&gt;@torestin&lt;/a&gt;&amp;nbsp;is whether randomized selection from the large data set is needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Feb 2017 01:28:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335794#M76041</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-25T01:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335805#M76050</link>
      <description>Hey thanks. Yes exactly. The small data sets will have many obs, so would&lt;BR /&gt;be very grateful if you or Patrick can suggest how this might be modified.&lt;BR /&gt;&lt;BR /&gt;The large set is randomly ordered. Just as a tangent, if a fail safe is&lt;BR /&gt;needed, would a randomly assigned starting point for the large set&lt;BR /&gt;do the trick?&lt;BR /&gt;&lt;BR /&gt;But anyway, I am starting to think I might have to do random sampling.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Sat, 25 Feb 2017 04:25:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335805#M76050</guid>
      <dc:creator>torestin</dc:creator>
      <dc:date>2017-02-25T04:25:19Z</dc:date>
    </item>
    <item>
      <title>Re: selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335819#M76058</link>
      <description>&lt;P&gt;Patrick's code also could apply to the case of multi-keys.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample_set;
  informat gender $1. ethnicity $1.;
  input serial gender ethnicity wage;
  datalines;
232 M W 230
232 M W 270
233 F B 240
;
run;

data huge_set;
  informat gender $1. ethnicity $1.;
  input id gender ethnicity wage;
  cards;
1 M W 254
2 M W 270
3 M B 255
4 M W 230
5 F B 211
6 F B 222
;
run;


data want(drop=sample_wage);
  set huge_set;
  if _n_=1 then
    do;
      if 0 then set sample_set(rename=(wage=sample_wage));
      dcl hash h1(dataset:'sample_set(rename=(wage=sample_wage))',multidata:'y');
      h1.defineKey('gender','ethnicity');
      h1.defineData('serial','sample_wage');
      h1.defineDone();
    end;

  rc=h1.find();
  do while(rc=0);
      if wage*0.9&amp;lt;=sample_wage&amp;lt;=wage*1.2 then 
        do;
          output;
          h1.removedup();
          if h1.num_items=0 then stop;
          leave;
        end;
      rc=h1.find_next(); 
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Feb 2017 06:29:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335819#M76058</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-02-25T06:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335835#M76065</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe your leave statement only exits the &lt;EM&gt;&lt;STRONG&gt;&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; wage&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0.9&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt;sample_wage&lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt;wage&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1.2&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; do&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN class="token punctuation"&gt; group, but not the outer&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;do while(rc&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;)&lt;/STRONG&gt;&lt;/EM&gt; do group.&amp;nbsp; It that's true then it seems possible that a single large observation could be matched with multiple small observations having the same gender/ethnicity and similar wage values.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Feb 2017 08:22:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335835#M76065</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-25T08:22:37Z</dc:date>
    </item>
    <item>
      <title>Re: selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335871#M76078</link>
      <description>&lt;P&gt;If the huge_set is in fact randomly ordered, and contains large numbers of candidates for each record to be matched from the sample set file, couldn't you accomplish the task by using code like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  do i=1 to nobs;
    set sample_set (rename=(gender=s_gender ethnicity=s_ethnicity wage=s_wage)) nobs=nobs;
    found=0;
    do j=1 by 1 until (found);
      set huge_set;
      if s_gender eq gender and
         s_ethnicity eq ethnicity and
         s_wage*0.9&amp;lt;=wage&amp;lt;=s_wage*1.2
         then do;
        found=1;
        output;
      end;
     end;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Feb 2017 18:40:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335871#M76078</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-25T18:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335882#M76086</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;: Shouldn't that be&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;      &lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; sample_wage&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0.9&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt;wage&lt;SPAN class="token operator"&gt;&amp;lt;=sample_&lt;/SPAN&gt;wage&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1.2&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;rather than&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;      &lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; wage&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0.9&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt;sample_wage&lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt;wage&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1.2&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Sat, 25 Feb 2017 20:36:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335882#M76086</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-25T20:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335883#M76087</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;: same comment I left for&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Shouldn't that be&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;      &lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; sample_wage&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0.9&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt;wage&lt;SPAN class="token operator"&gt;&amp;lt;=sample_&lt;/SPAN&gt;wage&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1.2&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;rather than&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;      &lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; wage&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0.9&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt;sample_wage&lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt;wage&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1.2&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Sat, 25 Feb 2017 20:37:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335883#M76087</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-25T20:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335906#M76100</link>
      <description>&lt;P&gt;Art asks:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;If the huge_set is in fact randomly ordered, and contains large numbers of candidates for each record to be matched from the sample set file, couldn't you accomplish the task by using code like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  do i=1 to nobs;
    set sample_set (rename=(gender=s_gender ethnicity=s_ethnicity wage=s_wage)) nobs=nobs;
    found=0;
    do j=1 by 1 until (found);
      set huge_set;
      if s_gender eq gender and
         s_ethnicity eq ethnicity and
         s_wage*0.9&amp;lt;=wage&amp;lt;=s_wage*1.2
         then do;
        found=1;
        output;
      end;
     end;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My answer: "yes".&amp;nbsp; Although I don't think you&amp;nbsp;need the outermost loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But&amp;nbsp;if one is really worried about a perverse situation in which HUGE_SET is exhausted before all the SAMPLE_SET is matched (say a rare ETHNICITY/GENDER/WAGE occurs early in HUGE_SET, but late in SAMPLE_SET), one could change&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; SET HUGE_SET&lt;BR /&gt;to&lt;BR /&gt;&amp;nbsp;&amp;nbsp; SET HUGE_SET HUGE_SET HUGE_SET open=defer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This just runs through HUGE_SET three times, if neccessary.&amp;nbsp; If the matching is satisfied during the first pass through&amp;nbsp; of huge_set (as per &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;'s reasonable expectation) , then this code will not add any time to completion (since it is the end of sample_set that terminates the data step).&amp;nbsp; This modificaton would just be an insurance policy against an unexpected situation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Feb 2017 21:57:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335906#M76100</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-25T21:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335920#M76110</link>
      <description>I thought about that. My question was with that doesn't the inner loop&lt;BR /&gt;starts from the beginning of the huge set every time? So if the top two in&lt;BR /&gt;the sample set are m w and the first record of the huge set matches. It&lt;BR /&gt;will just return that twice. Instead of searching down the list for another&lt;BR /&gt;match in huge set for no2 on the sample&lt;BR /&gt;&lt;BR /&gt;I suppose I could delete the match from the huge set every time. That might&lt;BR /&gt;work?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Sat, 25 Feb 2017 23:10:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335920#M76110</guid>
      <dc:creator>torestin</dc:creator>
      <dc:date>2017-02-25T23:10:19Z</dc:date>
    </item>
    <item>
      <title>Re: selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335922#M76112</link>
      <description>&lt;P&gt;Not sure which post you're replying to. With the code I suggested, the inner loop goes through the file sequentially. Records are only read once from the huge_set, and only until all records from the sample_set are matched.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The same occurs with the hash solutions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Sat, 25 Feb 2017 23:27:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335922#M76112</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-25T23:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335932#M76114</link>
      <description>&lt;P&gt;Mark,&lt;/P&gt;
&lt;P&gt;No . that would not happen. if that happened, OP must have replicated record in large table. That is another story.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2017 02:07:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/335932#M76114</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-02-26T02:07:33Z</dc:date>
    </item>
    <item>
      <title>Re: selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/336859#M76410</link>
      <description>Hi all. Thank you for all your help. I finally put it through the run today&lt;BR /&gt;and something rather strange happened. For some reason it seems to work&lt;BR /&gt;with only 1 condition. So it works fine when I tried to match wage lt&lt;BR /&gt;1.2*sample wage. Returns 6000 matches. Against 1m records. But adding any&lt;BR /&gt;other condition returns 5 observations. Doesn't matter if it's another&lt;BR /&gt;gender ethnicity or or an upper limit on income. Any guess where I went&lt;BR /&gt;wrong? I struggle to see why adding and wage lt 10*wage sample returns only&lt;BR /&gt;5 records or making an ethnicity match.....&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Wed, 01 Mar 2017 07:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/336859#M76410</guid>
      <dc:creator>torestin</dc:creator>
      <dc:date>2017-03-01T07:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: selecting only one match per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/336862#M76412</link>
      <description>&lt;P&gt;Post the where condition before and after the change.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 07:57:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-only-one-match-per-record/m-p/336862#M76412</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-01T07:57:02Z</dc:date>
    </item>
  </channel>
</rss>

