<?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: datastep:  if observation occurs in another dataset then do certain things in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/datastep-if-observation-occurs-in-another-dataset-then-do/m-p/270301#M53685</link>
    <description>&lt;P&gt;It is creating(initiate)&amp;nbsp;variables in PDV &amp;nbsp;which are&amp;nbsp;in&amp;nbsp;CNTY_LOOKUP table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way is &amp;nbsp;hard code Like :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;length&amp;nbsp;CNTY_CODE2 &amp;nbsp;$ 8&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;instead of&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if 0 then set ....&lt;/P&gt;</description>
    <pubDate>Fri, 13 May 2016 09:25:28 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-05-13T09:25:28Z</dc:date>
    <item>
      <title>datastep:  if observation occurs in another dataset then do certain things</title>
      <link>https://communities.sas.com/t5/SAS-Programming/datastep-if-observation-occurs-in-another-dataset-then-do/m-p/270278#M53677</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dear Community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 2 datasets:&amp;nbsp; dataset A and dataset B.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dataset A contains several observations with unique identifier KEY, STATUS, name, address, etc...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dataset B contains only 1 variable KEY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I would like to do:&amp;nbsp; for each observation in A, I want to check if the value for KEY occurs in dataset B, and if so, STATUS in dataset A has to change. (let's say status = 'Z')&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can manage that with SQL, by which I first create a new table based on a join of the 2 tables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I would like to know if there is a way to manage this easily in a datastep.&lt;/P&gt;
&lt;P&gt;I would expect something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data table_A_out;&lt;/P&gt;
&lt;P&gt;set table_A_in;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if KEY in ( table_B.KEY) then STATUS = 'Z';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it doesn't work that way...&lt;/P&gt;
&lt;P&gt;Any advise would be appreciated.&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>Fri, 13 May 2016 07:29:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/datastep-if-observation-occurs-in-another-dataset-then-do/m-p/270278#M53677</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2016-05-13T07:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: datastep:  if observation occurs in another dataset then do certain things</title>
      <link>https://communities.sas.com/t5/SAS-Programming/datastep-if-observation-occurs-in-another-dataset-then-do/m-p/270285#M53680</link>
      <description>&lt;P&gt;Hash Table&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data IFILE ;
input  STATUS $       SEND_CNTY $;
cards;
T123                    EH
T456                    ZM 
T678                     US
T444                     ZW
;
run;
data CNTY_LOOKUP ;
input  CNTY_CODE2 $;
cards;
 EH
  YE
 ZM
 ZW
;
run;
data want;
 if _n_=1 then do;
  if 0 then set CNTY_LOOKUP;
  declare hash h(dataset:'CNTY_LOOKUP');
  h.definekey('CNTY_CODE2');
  h.definedone();
 end;
set IFILE;
if h.check(key:SEND_CNTY)=0 then STATUS ='Z';

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 May 2016 08:00:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/datastep-if-observation-occurs-in-another-dataset-then-do/m-p/270285#M53680</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-05-13T08:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: datastep:  if observation occurs in another dataset then do certain things</title>
      <link>https://communities.sas.com/t5/SAS-Programming/datastep-if-observation-occurs-in-another-dataset-then-do/m-p/270286#M53681</link>
      <description>&lt;P&gt;Thank you for this very compact code.&amp;nbsp; It is what I was looking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing I don't understand:&amp;nbsp; the second if:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if 0 then ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If what exactly is zero?&amp;nbsp; And what does it means in this context?&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2016 08:20:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/datastep-if-observation-occurs-in-another-dataset-then-do/m-p/270286#M53681</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2016-05-13T08:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: datastep:  if observation occurs in another dataset then do certain things</title>
      <link>https://communities.sas.com/t5/SAS-Programming/datastep-if-observation-occurs-in-another-dataset-then-do/m-p/270301#M53685</link>
      <description>&lt;P&gt;It is creating(initiate)&amp;nbsp;variables in PDV &amp;nbsp;which are&amp;nbsp;in&amp;nbsp;CNTY_LOOKUP table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way is &amp;nbsp;hard code Like :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;length&amp;nbsp;CNTY_CODE2 &amp;nbsp;$ 8&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;instead of&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if 0 then set ....&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2016 09:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/datastep-if-observation-occurs-in-another-dataset-then-do/m-p/270301#M53685</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-05-13T09:25:28Z</dc:date>
    </item>
  </channel>
</rss>

