<?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: Compare variables from tables and only take occurring ones in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Compare-variables-from-tables-and-only-take-occurring-ones/m-p/636589#M78122</link>
    <description>&lt;P&gt;Thank you very much fot the quick response!&lt;/P&gt;&lt;P&gt;Yes, I have to create a new dataset.&lt;/P&gt;</description>
    <pubDate>Wed, 01 Apr 2020 15:36:45 GMT</pubDate>
    <dc:creator>Jay_Aguilar</dc:creator>
    <dc:date>2020-04-01T15:36:45Z</dc:date>
    <item>
      <title>Compare variables from tables and only take occurring ones</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Compare-variables-from-tables-and-only-take-occurring-ones/m-p/636580#M78117</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a list which looks like this (table 1):&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;information&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;abc&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;def&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;ghi&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I now want to get data from another table (table 2) which has many more ID's&amp;nbsp; (e.g. ID 1 to 10) but I only want those datasets which have the ID defined in my first table (table 1). I do not want to indicate which ID's to take via a WHERE statement and write every ID which should be taken but somehow make it more flexible. So if at one point in time I need to add an ID to my first table (table 1),&amp;nbsp; it automatically takes the added ID into account when getting data from my second table (table 2). I guess I am looking for something like the VLOOKUP in excel, just that I do not want to join the the tables.&lt;/P&gt;&lt;P&gt;I hope I could make clear what I need and would be very happy if someone could help me with that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2020 15:10:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Compare-variables-from-tables-and-only-take-occurring-ones/m-p/636580#M78117</guid>
      <dc:creator>Jay_Aguilar</dc:creator>
      <dc:date>2020-04-01T15:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: Compare variables from tables and only take occurring ones</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Compare-variables-from-tables-and-only-take-occurring-ones/m-p/636583#M78118</link>
      <description>&lt;P&gt;Are you asking to make a new dataset that is a subset of an existing dataset?&lt;/P&gt;
&lt;P&gt;Let's call you list of id table as LIST, the existing dataset has HAVE and the desired result as WANT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use data step with MERGE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge have list(in=inlist);
  by id;
  if inlist;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note this requires that both dataset as sorted.&lt;/P&gt;
&lt;P&gt;You can use an SQL query.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select * from have
where id in (select id from list)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Either of these can be created as views instead of tables if you the results to automatically reflect changes to HAVE and LIST.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2020 15:19:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Compare-variables-from-tables-and-only-take-occurring-ones/m-p/636583#M78118</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-01T15:19:24Z</dc:date>
    </item>
    <item>
      <title>Re: Compare variables from tables and only take occurring ones</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Compare-variables-from-tables-and-only-take-occurring-ones/m-p/636587#M78120</link>
      <description>&lt;P&gt;A more modern approach to do a lookup is the hash object:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if _n_ = 1
then do;
  declare hash lookup (dataset:"list (keep=id)");
  lookup.definekey("id");
  lookup.definedone();
end;
if lookup.find() = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that this needs to be re-run anytime one of the input datasets changes (a view would not need this), but if the result is to be used multiple times, it will provide better performance.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2020 15:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Compare-variables-from-tables-and-only-take-occurring-ones/m-p/636587#M78120</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-01T15:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: Compare variables from tables and only take occurring ones</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Compare-variables-from-tables-and-only-take-occurring-ones/m-p/636589#M78122</link>
      <description>&lt;P&gt;Thank you very much fot the quick response!&lt;/P&gt;&lt;P&gt;Yes, I have to create a new dataset.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2020 15:36:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Compare-variables-from-tables-and-only-take-occurring-ones/m-p/636589#M78122</guid>
      <dc:creator>Jay_Aguilar</dc:creator>
      <dc:date>2020-04-01T15:36:45Z</dc:date>
    </item>
  </channel>
</rss>

