<?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: Extracting all records that share variable 2 values, where at least one variable 1 value is = XX in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971307#M43413</link>
    <description>All suggestions in this thread worked, but the hash object technique seems to be the most efficient. Thank you!</description>
    <pubDate>Tue, 22 Jul 2025 15:30:42 GMT</pubDate>
    <dc:creator>jibra</dc:creator>
    <dc:date>2025-07-22T15:30:42Z</dc:date>
    <item>
      <title>Extracting all records that share variable 2 values, where at least one variable 1 value is = XX</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971256#M43402</link>
      <description>&lt;P&gt;Here's a sample of what I have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="2" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl64" style="height: 15.0pt; width: 48pt;"&gt;&lt;STRONG&gt;var1&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="64" class="xl64" style="border-left: none; width: 48pt;"&gt;&lt;STRONG&gt;var2&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl65" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;AA&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Paul&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl65" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;BB&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Paul&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl65" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;XX&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Paul&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt; border-top: none;"&gt;dd&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;Mike&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt; border-top: none;"&gt;pp&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;Mike&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl65" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;cc&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Dave&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl65" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;ee&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Dave&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl65" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;ff&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Dave&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl65" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;gg&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Dave&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl65" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;XX&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Dave&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl65" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;hh&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Ken&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl65" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;ii&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Ken&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl65" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;jj&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Ken&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl65" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;XX&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Ken&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt; border-top: none;"&gt;kk&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;Rick&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt; border-top: none;"&gt;ll&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;Rick&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt; border-top: none;"&gt;mm&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;Rick&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a sample of what I want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="2" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl65" style="height: 15.0pt; width: 48pt;"&gt;&lt;STRONG&gt;var1&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;&lt;STRONG&gt;var2&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;AA&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Paul&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;BB&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Paul&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;XX&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Paul&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;cc&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Dave&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;ee&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Dave&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;ff&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Dave&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;gg&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Dave&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;XX&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Dave&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;hh&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Ken&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;ii&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Ken&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;jj&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Ken&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl66" style="height: 15.0pt; border-top: none;"&gt;&lt;STRONG&gt;XX&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;Ken&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jul 2025 18:57:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971256#M43402</guid>
      <dc:creator>jibra</dc:creator>
      <dc:date>2025-07-21T18:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting all records that share variable 2 values, where at least one variable 1 value is = XX</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971257#M43403</link>
      <description>&lt;P&gt;Any suggestion would be welcome.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jul 2025 18:57:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971257#M43403</guid>
      <dc:creator>jibra</dc:creator>
      <dc:date>2025-07-21T18:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting all records that share variable 2 values, where at least one variable 1 value is = XX</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971265#M43404</link>
      <description>&lt;P&gt;Please post your sample data as code (DATA step with CARDS statement).&amp;nbsp; Also please post the code you have tried.&amp;nbsp; This will help others help you.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jul 2025 19:39:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971265#M43404</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2025-07-21T19:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting all records that share variable 2 values, where at least one variable 1 value is = XX</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971270#M43405</link>
      <description>&lt;P&gt;Trying to guess what you mean it sounds like you want all observations for any person that has VAR1='XX'.&amp;nbsp; (Note question are easier to read if the details are in the body of the question and not just the subject line.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SQL should make that simple.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
  select * from have
  where var2 in
    (select var2 from have where var1='XX')
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jul 2025 20:10:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971270#M43405</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-07-21T20:10:58Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting all records that share variable 2 values, where at least one variable 1 value is = XX</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971277#M43406</link>
      <description>&lt;P&gt;Double DO method:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until (last.var2);
  set have;
  by var2 notsorted;
  if var1 = "XX" then flag = 1;
end;
do until (last.var2);
  set have;
  by var2 notsorted;
  if flag then output;
end;
drop flag;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Jul 2025 21:18:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971277#M43406</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-07-21T21:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting all records that share variable 2 values, where at least one variable 1 value is = XX</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971279#M43407</link>
      <description>&lt;P&gt;Or a data step hash table lookup&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if _n_=1 then
    do;
      dcl hash h1(dataset:'have(where=(var1=:"XX"))');
      h1.defineKey('var2');
      h1.defineDone();
    end;
  set have;
  if h1.check()=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Jul 2025 23:37:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971279#M43407</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2025-07-21T23:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting all records that share variable 2 values, where at least one variable 1 value is = XX</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971284#M43408</link>
      <description>&lt;P&gt;If the dataset is not particularly big, then I think your best option is the hash object technique suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;. The code is simple.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That solution requires reading the data in two unsynchronized data streams, which could create a performance hit in the case of large datasets, due to disk activity.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now if the data were sorted by VAR2, you could do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge have (where=(var1='XX')  in=wanted) 
        have;
  by var2;
  if wanted;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which synchronizes the data streams and reduces disk activity.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your data are not sorted by VAR2, although it is grouped by VAR2.&amp;nbsp; So you can generate data stream synchronization with code such as this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  set have (where=(var1='XX') rename=(var2=_var2));

  do until (last.var2=1 and var2=_var2);
    set have;
    by var2 notsorted;
    if var2=_var2 then output; 
  end;
run;
&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;The above assumes no more than one var1='XX' for any given VAR2.&amp;nbsp; If you can have two or more var1='XX' cases, then:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  set have (where=(var1='XX') rename=(var2=_var2));
  by _var2 notsorted;

  if last._var2 then do until (last.var2=1 and var2=_var2);
    set have;
    by var2 notsorted;
    if var2=_var2 then output; 
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And yes, the degree of synchronization achieved would depend on the distribution of the "XX" cases.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jul 2025 13:56:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971284#M43408</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2025-07-22T13:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting all records that share variable 2 values, where at least one variable 1 value is = XX</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971287#M43409</link>
      <description>&lt;P&gt;Just to have (more) complete picture.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The power of IN operator over a macro variable with constant list of&amp;nbsp;values:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input var1 $ var2 $;
cards;
AA	Paul
BB	Paul
XX	Paul
dd	Mike
pp	Mike
cc	Dave
ee	Dave
ff	Dave
gg	Dave
XX	Dave
hh	Ken
ii	Ken
jj	Ken
XX	Ken
kk	Rick
ll	Rick
mm	Rick
;
run;
proc print data=have;
run;

proc SQL noprint;
  select 
  distinct quote(var2)
  into :myList separated by " "
  from have
  where var1 = "XX"
  ;
quit;

data want;
  set have;
  where var2 in (&amp;amp;myList.);
run;
proc print data=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;BTW. Just for fun, here is an article "&lt;A href="https://www.lexjansen.com/pharmasug/2025/HT/PharmaSUG-2025-HT-115.pdf" target="_self"&gt;&lt;EM&gt;Route Sixty-Six to SAS Programming, or 63 (+3) Syntax Snippets for a Table Look-up Task, or How to Learn SAS by Solving Only One Exercise!&lt;/EM&gt;&lt;/A&gt;" that provides 66 examples of solving the table-lookup task &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jul 2025 07:35:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971287#M43409</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-07-22T07:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting all records that share variable 2 values, where at least one variable 1 value is = XX</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971291#M43410</link>
      <description>&lt;P&gt;Or you would like to get it automatically ? and not type XX by hand ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input var1 $ var2 $;
cards;
AA	Paul
BB	Paul
XX	Paul
dd	Mike
pp	Mike
cc	Dave
ee	Dave
ff	Dave
gg	Dave
XX	Dave
hh	Ken
ii	Ken
jj	Ken
XX	Ken
kk	Rick
ll	Rick
mm	Rick
;

proc sql;
create table want as
select * from have where var2 in 
(
select distinct var2 from have group by var1 having count(distinct var2)&amp;gt;1
)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Jul 2025 08:31:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971291#M43410</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-07-22T08:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting all records that share variable 2 values, where at least one variable 1 value is = XX</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971292#M43411</link>
      <description>&lt;P&gt;I'm not sure if this is possible to have such data, but what about "Joe" (last record) ?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input var1 $ var2 $;
cards;
AA	Paul
BB	Paul
XX	Paul
dd	Mike
pp	Mike
cc	Dave
ee	Dave
ff	Dave
gg	Dave
XX	Dave
hh	Ken
ii	Ken
jj	Ken
XX	Ken
kk	Rick
ll	Rick
mm	Rick
AA	Joe
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jul 2025 08:54:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971292#M43411</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-07-22T08:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting all records that share variable 2 values, where at least one variable 1 value is = XX</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971294#M43412</link>
      <description>yabwom,&lt;BR /&gt;I don't know either .&lt;BR /&gt;It is all depend on what the OP is looking for.&lt;BR /&gt;The code I posted is just guessing the intention of OP .</description>
      <pubDate>Tue, 22 Jul 2025 09:21:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971294#M43412</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-07-22T09:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting all records that share variable 2 values, where at least one variable 1 value is = XX</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971307#M43413</link>
      <description>All suggestions in this thread worked, but the hash object technique seems to be the most efficient. Thank you!</description>
      <pubDate>Tue, 22 Jul 2025 15:30:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971307#M43413</guid>
      <dc:creator>jibra</dc:creator>
      <dc:date>2025-07-22T15:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting all records that share variable 2 values, where at least one variable 1 value is = XX</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971310#M43414</link>
      <description>&lt;P&gt;Most efficient of all the solutions offered.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jul 2025 15:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-all-records-that-share-variable-2-values-where-at/m-p/971310#M43414</guid>
      <dc:creator>jibra</dc:creator>
      <dc:date>2025-07-22T15:41:24Z</dc:date>
    </item>
  </channel>
</rss>

