<?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 Partial and/or full matching of two variables of varying length in different input files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Partial-and-or-full-matching-of-two-variables-of-varying-length/m-p/594267#M170696</link>
    <description>&lt;P&gt;I have two input files. The first one, "failed_jobs", is a list of failed jobs. These will be anywhere from 1-64 characters and may have a period "." in the jobs name at different places. The second is "exceptions", these can also be from 1-64 characters with the possibility of a period in the name. I need to exclude any job that is on the exceptions list. The exceptions may be the entire jobs name, or it may anywhere from the first 2 charters to 64. Because of the variable length matching, I am having a had time figuring out how to make this happen. Any thought would be welcome.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this example jobs PESPCD01, any PCAIM* jobs and PDUKCM01.WEB02 should be the ones excluded from the list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data failed_jobs;&lt;BR /&gt;input error_code $ 1 - 8 jobs $ 9 - 73;&lt;BR /&gt;datalines;&lt;BR /&gt;ESPPS06 PESPCD01&lt;BR /&gt;ESPPS06 PESPCDAD&lt;BR /&gt;ESPPS06 POWBCMAA&lt;BR /&gt;ESPPS06 PCAICA00&lt;BR /&gt;ESPPS06 PCAICM02&lt;BR /&gt;ESPPS06 PCAICM03&lt;BR /&gt;ESPPS06 PCAICM04&lt;BR /&gt;ESPPS06 PCAICM05&lt;BR /&gt;ESPPS06 PDUKCM01&lt;BR /&gt;ESPPS06 PDUKCM01.WEB02&lt;BR /&gt;ESPPS06 PESPCD02&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data exceptions;&lt;BR /&gt;input error_code $ 1 - 8 job_exceptions $ 9 - 73;&lt;BR /&gt;datalines;&lt;BR /&gt;ESPPS06 PESPCD01&lt;BR /&gt;ESPPS06 PCAIM&lt;BR /&gt;ESPPS06 POWBCAXX&lt;BR /&gt;ESPPS06 PDUKCM01.W&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;* final output of failed jobs;&lt;BR /&gt;ESPPS06 PESPCDAD&lt;BR /&gt;ESPPS06 POWBCMAA&lt;BR /&gt;ESPPS06 PCAICA00&lt;BR /&gt;ESPPS06 PESPCD02&lt;BR /&gt;ESPPS06 PDUKCM01&lt;/P&gt;</description>
    <pubDate>Sat, 05 Oct 2019 11:49:24 GMT</pubDate>
    <dc:creator>a079011</dc:creator>
    <dc:date>2019-10-05T11:49:24Z</dc:date>
    <item>
      <title>Partial and/or full matching of two variables of varying length in different input files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Partial-and-or-full-matching-of-two-variables-of-varying-length/m-p/594267#M170696</link>
      <description>&lt;P&gt;I have two input files. The first one, "failed_jobs", is a list of failed jobs. These will be anywhere from 1-64 characters and may have a period "." in the jobs name at different places. The second is "exceptions", these can also be from 1-64 characters with the possibility of a period in the name. I need to exclude any job that is on the exceptions list. The exceptions may be the entire jobs name, or it may anywhere from the first 2 charters to 64. Because of the variable length matching, I am having a had time figuring out how to make this happen. Any thought would be welcome.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this example jobs PESPCD01, any PCAIM* jobs and PDUKCM01.WEB02 should be the ones excluded from the list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data failed_jobs;&lt;BR /&gt;input error_code $ 1 - 8 jobs $ 9 - 73;&lt;BR /&gt;datalines;&lt;BR /&gt;ESPPS06 PESPCD01&lt;BR /&gt;ESPPS06 PESPCDAD&lt;BR /&gt;ESPPS06 POWBCMAA&lt;BR /&gt;ESPPS06 PCAICA00&lt;BR /&gt;ESPPS06 PCAICM02&lt;BR /&gt;ESPPS06 PCAICM03&lt;BR /&gt;ESPPS06 PCAICM04&lt;BR /&gt;ESPPS06 PCAICM05&lt;BR /&gt;ESPPS06 PDUKCM01&lt;BR /&gt;ESPPS06 PDUKCM01.WEB02&lt;BR /&gt;ESPPS06 PESPCD02&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data exceptions;&lt;BR /&gt;input error_code $ 1 - 8 job_exceptions $ 9 - 73;&lt;BR /&gt;datalines;&lt;BR /&gt;ESPPS06 PESPCD01&lt;BR /&gt;ESPPS06 PCAIM&lt;BR /&gt;ESPPS06 POWBCAXX&lt;BR /&gt;ESPPS06 PDUKCM01.W&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;* final output of failed jobs;&lt;BR /&gt;ESPPS06 PESPCDAD&lt;BR /&gt;ESPPS06 POWBCMAA&lt;BR /&gt;ESPPS06 PCAICA00&lt;BR /&gt;ESPPS06 PESPCD02&lt;BR /&gt;ESPPS06 PDUKCM01&lt;/P&gt;</description>
      <pubDate>Sat, 05 Oct 2019 11:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Partial-and-or-full-matching-of-two-variables-of-varying-length/m-p/594267#M170696</guid>
      <dc:creator>a079011</dc:creator>
      <dc:date>2019-10-05T11:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: Partial and/or full matching of two variables of varying length in different input files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Partial-and-or-full-matching-of-two-variables-of-varying-length/m-p/594269#M170698</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12971"&gt;@a079011&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select a.* from failed_jobs a
left join exceptions b
on /* a.error_code=b.error_code &amp;amp; */ jobs eqt job_exceptions &amp;amp; length(job_exceptions)&amp;lt;=length(jobs)
where job_exceptions=' ';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Feel free to use the additional condition on &lt;FONT face="courier new,courier"&gt;error_code&lt;/FONT&gt;, which I have commented out, if you want to include it.&lt;/P&gt;
&lt;P&gt;Please note that your "final output" is not quite consistent with the description: The PCAI&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;C&lt;/STRONG&gt;&lt;/FONT&gt;M&lt;EM&gt;xx&lt;/EM&gt; jobs seem to have been eliminated by PCAIM.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Oct 2019 13:05:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Partial-and-or-full-matching-of-two-variables-of-varying-length/m-p/594269#M170698</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-10-05T13:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: Partial and/or full matching of two variables of varying length in different input files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Partial-and-or-full-matching-of-two-variables-of-varying-length/m-p/594288#M170708</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12971"&gt;@a079011&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;In addition to the&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;'s offering, I'd suggest:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data failed_jobs ;                                                                                                                                                                                                                                              
  input error_code $ 1-8 jobs $ 9-73 ;                                                                                                                                                                                                                          
  cards ;                                                                                                                                                                                                                                                       
ESPPS06 PESPCD01                                                                                                                                                                                                                                                
ESPPS06 PESPCDAD                                                                                                                                                                                                                                                
ESPPS06 POWBCMAA                                                                                                                                                                                                                                                
ESPPS06 PCAICA00                                                                                                                                                                                                                                                
ESPPS06 PCAICM02                                                                                                                                                                                                                                                
ESPPS06 PCAICM03                                                                                                                                                                                                                                                
ESPPS06 PCAICM04                                                                                                                                                                                                                                                
ESPPS06 PCAICM05                                                                                                                                                                                                                                                
ESPPS06 PDUKCM01                                                                                                                                                                                                                                                
ESPPS06 PDUKCM01.WEB02                                                                                                                                                                                                                                          
ESPPS06 PESPCD02                                                                                                                                                                                                                                                
;                                                                                                                                                                                                                                                               
run ;                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                
data exceptions ;                                                                                                                                                                                                                                               
  input error_code $ 1-8 job_exceptions $ 9-73 ;                                                                                                                                                                                                                
  cards ;                                                                                                                                                                                                                                                       
ESPPS06 PESPCD01                                                                                                                                                                                                                                                
ESPPS06 PCAICM                                                                                                                                                                                                                                                  
ESPPS06 POWBCAXX                                                                                                                                                                                                                                                
ESPPS06 PDUKCM01.W                                                                                                                                                                                                                                              
;                                                                                                                                                                                                                                                               
run ;                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                
option msglevel=i ;                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                
proc sql _method ;                                                                                                                                                                                                                                              
  create table want as                                                                                                                                                                                                                                          
  select * from failed_jobs f                                                                                                                                                                                                                                   
  where not exists                                                                                                                                                                                                                                              
 (select 1 from exceptions x                                                                                                                                                                                                                                    
  where find (f.jobs, trim (x.job_exceptions)) = 1                                                                                                                                                                                                              
  and   f.error_code = x.error_code                                                                                                                                                                                                                             
  ) ;                                                                                                                                                                                                                                                           
quit ;                                          &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;One advantage of doing it using the EXISTS subquery clause instead of a subset left join (as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;has suggested) is that the optimizer doesn't choose to create a Cartesian product and then subset it even if the AND condition above is not included in the query. Also, methinks that using the FIND function in the above manner (it basically asks if &lt;EM&gt;job_exceptions&lt;/EM&gt; is part of &lt;EM&gt;jobs&lt;/EM&gt; starting at position 1) is simpler than the extra comparison between the lengths of &lt;EM&gt;jobs&lt;/EM&gt; and &lt;EM&gt;job_exceptions&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Oct 2019 19:56:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Partial-and-or-full-matching-of-two-variables-of-varying-length/m-p/594288#M170708</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-05T19:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: Partial and/or full matching of two variables of varying length in different input files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Partial-and-or-full-matching-of-two-variables-of-varying-length/m-p/594360#M170749</link>
      <description>&lt;P&gt;Thank you! I have tested a little, and this seems to be working as expected.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2019 19:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Partial-and-or-full-matching-of-two-variables-of-varying-length/m-p/594360#M170749</guid>
      <dc:creator>a079011</dc:creator>
      <dc:date>2019-10-06T19:03:41Z</dc:date>
    </item>
  </channel>
</rss>

