<?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: Finding matching observations? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-matching-observations/m-p/837849#M331302</link>
    <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Observations;
input obs USL :$100.;
datalines;
1  US0003,US0005,USL00V                                           
2  USL007,USL00D                                                  
3  USL009,USL00A,USL00J,USL019                                    
4  US0003,US0005,USL009,USL00V                                    
5  US0003,US0004,US0005,US0007,US0008,US000A,US000D,US000K,USL00V 
6  USL006,USL00B,USL00D                                           
7  USL003,USL008,USL00G,USL00M                                    
8  USL00A,USL00J,USL012,USV002,USV003                             
9  USL00B,USL00E,USL00J                                           
10 US000J,USL00U,USL00V                                           
;

data Stations;
input station_id $;
datalines;
US0001
US0002
US0003
US0004
US0005
US0006
US0007
US0008
US0009
US000A
;

data Matches(drop = i station_id);
   if _N_ = 1 then do;
      dcl hash h(dataset : 'Stations');
      h.definekey('station_id');
      h.definedone();
   end;

   set Observations;

   do i = 1 to countw(USL);
      station_id = scan(USL, i, ',');
      if h.check() = 0 then do;
         output;
         leave;
      end;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;obs USL
1   US0003,US0005,USL00V
4   US0003,US0005,USL009,USL00V
5   US0003,US0004,US0005,US0007,US0008,US000A,US000D,US000K,USL00V&lt;/PRE&gt;</description>
    <pubDate>Tue, 11 Oct 2022 13:20:15 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-10-11T13:20:15Z</dc:date>
    <item>
      <title>Finding matching observations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-matching-observations/m-p/837846#M331299</link>
      <description>&lt;P&gt;Esteemed Advisers:&lt;/P&gt;
&lt;P&gt;I have two datasets, Observations and Stations. I want to search the variable USL in Observations for every instance of a station_id from the dataset of Stations. In this simple exemplar case, that would be observations 1,4, and 5. These three observations&amp;nbsp; dataset Observations would then be written to a third dataset called Matches. How can I accomplish this?&amp;nbsp; Thanks in advance for taking a look at this!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dataset Observations&lt;BR /&gt;Obs USL&lt;BR /&gt;1 US0003,US0005,USL00V&lt;BR /&gt;2 USL007,USL00D&lt;BR /&gt;3 USL009,USL00A,USL00J,USL019&lt;BR /&gt;4 US0003,US0005,USL009,USL00V&lt;BR /&gt;5 US0003,US0004,US0005,US0007,US0008,US000A,US000D,US000K,USL00V&lt;BR /&gt;6 USL006,USL00B,USL00D&lt;BR /&gt;7 USL003,USL008,USL00G,USL00M&lt;BR /&gt;8 USL00A,USL00J,USL012,USV002,USV003&lt;BR /&gt;9 USL00B,USL00E,USL00J&lt;BR /&gt;10 US000J,USL00U,USL00V&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dataset Stations&lt;BR /&gt;Obs station_id&lt;BR /&gt;1 US0001&lt;BR /&gt;2 US0002&lt;BR /&gt;3 US0003&lt;BR /&gt;4 US0004&lt;BR /&gt;5 US0005&lt;BR /&gt;6 US0006&lt;BR /&gt;7 US0007&lt;BR /&gt;8 US0008&lt;BR /&gt;9 US0009&lt;BR /&gt;10 US000A&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2022 13:09:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-matching-observations/m-p/837846#M331299</guid>
      <dc:creator>genemroz</dc:creator>
      <dc:date>2022-10-11T13:09:30Z</dc:date>
    </item>
    <item>
      <title>Re: Finding matching observations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-matching-observations/m-p/837849#M331302</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Observations;
input obs USL :$100.;
datalines;
1  US0003,US0005,USL00V                                           
2  USL007,USL00D                                                  
3  USL009,USL00A,USL00J,USL019                                    
4  US0003,US0005,USL009,USL00V                                    
5  US0003,US0004,US0005,US0007,US0008,US000A,US000D,US000K,USL00V 
6  USL006,USL00B,USL00D                                           
7  USL003,USL008,USL00G,USL00M                                    
8  USL00A,USL00J,USL012,USV002,USV003                             
9  USL00B,USL00E,USL00J                                           
10 US000J,USL00U,USL00V                                           
;

data Stations;
input station_id $;
datalines;
US0001
US0002
US0003
US0004
US0005
US0006
US0007
US0008
US0009
US000A
;

data Matches(drop = i station_id);
   if _N_ = 1 then do;
      dcl hash h(dataset : 'Stations');
      h.definekey('station_id');
      h.definedone();
   end;

   set Observations;

   do i = 1 to countw(USL);
      station_id = scan(USL, i, ',');
      if h.check() = 0 then do;
         output;
         leave;
      end;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;obs USL
1   US0003,US0005,USL00V
4   US0003,US0005,USL009,USL00V
5   US0003,US0004,US0005,US0007,US0008,US000A,US000D,US000K,USL00V&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Oct 2022 13:20:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-matching-observations/m-p/837849#M331302</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-10-11T13:20:15Z</dc:date>
    </item>
    <item>
      <title>Re: Finding matching observations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-matching-observations/m-p/837855#M331306</link>
      <description>&lt;P&gt;Thanks for the prompt and helpful reply (I think...). Your solution worked on my larger datasets. But now I have to go and learn hash object code to figure out what just happened here.&amp;nbsp; But I'm truly grateful and marking this solution as accepted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Gene&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2022 13:45:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-matching-observations/m-p/837855#M331306</guid>
      <dc:creator>genemroz</dc:creator>
      <dc:date>2022-10-11T13:45:24Z</dc:date>
    </item>
  </channel>
</rss>

