<?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 Selecting Based on Pattern Matching in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Selecting-Based-on-Pattern-Matching/m-p/540195#M148978</link>
    <description>&lt;P&gt;I have a series of aviation messages that come in as text. I need to be able to use a "like" type of command.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At present I have&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(case when t1.MSG_RAW_TXT contains " CYQXZZZ" then 1 else 0 end) AS GANDER_VOICE&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, there can be messages in the&amp;nbsp;MSG_RAW_TXT variable that are misidentified.&amp;nbsp; The ones I want ALWAYS have 6 numbers before it....for example&amp;nbsp;&lt;SPAN&gt;EIAAYSYX&amp;nbsp;&lt;/SPAN&gt;030800&lt;SPAN&gt; CYQXZZZ would be a valid message to set GANDER_VOICE=1 because of the 030800 in front of&amp;nbsp;CYQXZZZ. This example:&amp;nbsp;EIAAYSYX&amp;nbsp;CYQXZZZ would not be a valid message to set GANDER_VOICE=1.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am not sure how this could be done in SAS.&amp;nbsp; A Microsoft SQL programmer at work here suggested something along the lines of:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Like ‘[0-9][0-9][0-9] [0-9] [0-9] [0-9] CYQXZZZ’&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This would look for any sequence in the&amp;nbsp;MSG_RAW_TXT variable that has a 6 digit number (each number is from 0-9 as stated above), then a space and then the&amp;nbsp;CYQXZZZ.&amp;nbsp; In this general case we would set&amp;nbsp;GANDER_VOICE=1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for any advice&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Mar 2019 20:09:15 GMT</pubDate>
    <dc:creator>BCNAV</dc:creator>
    <dc:date>2019-03-04T20:09:15Z</dc:date>
    <item>
      <title>Selecting Based on Pattern Matching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-Based-on-Pattern-Matching/m-p/540195#M148978</link>
      <description>&lt;P&gt;I have a series of aviation messages that come in as text. I need to be able to use a "like" type of command.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At present I have&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(case when t1.MSG_RAW_TXT contains " CYQXZZZ" then 1 else 0 end) AS GANDER_VOICE&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, there can be messages in the&amp;nbsp;MSG_RAW_TXT variable that are misidentified.&amp;nbsp; The ones I want ALWAYS have 6 numbers before it....for example&amp;nbsp;&lt;SPAN&gt;EIAAYSYX&amp;nbsp;&lt;/SPAN&gt;030800&lt;SPAN&gt; CYQXZZZ would be a valid message to set GANDER_VOICE=1 because of the 030800 in front of&amp;nbsp;CYQXZZZ. This example:&amp;nbsp;EIAAYSYX&amp;nbsp;CYQXZZZ would not be a valid message to set GANDER_VOICE=1.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am not sure how this could be done in SAS.&amp;nbsp; A Microsoft SQL programmer at work here suggested something along the lines of:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Like ‘[0-9][0-9][0-9] [0-9] [0-9] [0-9] CYQXZZZ’&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This would look for any sequence in the&amp;nbsp;MSG_RAW_TXT variable that has a 6 digit number (each number is from 0-9 as stated above), then a space and then the&amp;nbsp;CYQXZZZ.&amp;nbsp; In this general case we would set&amp;nbsp;GANDER_VOICE=1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for any advice&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 20:09:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-Based-on-Pattern-Matching/m-p/540195#M148978</guid>
      <dc:creator>BCNAV</dc:creator>
      <dc:date>2019-03-04T20:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting Based on Pattern Matching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-Based-on-Pattern-Matching/m-p/540199#M148981</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/142314"&gt;@BCNAV&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can extract the wanted word with a regular expression like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data _null_;
	MSG_RAW_TXT = 'EIAAYSYX 030800 CYQXZZZ xyz';
	b = prxchange('s/(.*\b\d{6}) (\w+)(.*)/$2/',-1,MSG_RAW_TXT);
	put b=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It might be a better approach to extract the airport to a new variable.You could do that in a data step, and then use that&amp;nbsp; in your SQL, if for some reason you want the boolean variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 20:32:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-Based-on-Pattern-Matching/m-p/540199#M148981</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-03-04T20:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting Based on Pattern Matching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-Based-on-Pattern-Matching/m-p/540201#M148983</link>
      <description>&lt;P&gt;You have a sequence of space separated words in a character variable, call it TXT.&amp;nbsp;&amp;nbsp; You can&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Set gander=0.&lt;/LI&gt;
&lt;LI&gt;Find the word position W&amp;nbsp;of "CYQXZZZ" in TXT&amp;nbsp; (the findw function).&lt;/LI&gt;
&lt;LI&gt;If&amp;nbsp; W&amp;gt;1 you can extract word number W-1 (the scan function), call it PRIOR_WRD&lt;/LI&gt;
&lt;LI&gt;If
&lt;OL&gt;
&lt;LI&gt;PRIOR_WRD is exactly 6 characters, and&lt;/LI&gt;
&lt;LI&gt;non of the characters is a non-digit&lt;/LI&gt;
&lt;LI&gt;then gander=1&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input txt $50.;
  put txt=;
datalines;
EIAAYSYX 030800 CYQXZZZ
EIAAYSYX CYQXZZZ
run;

data want (drop=prior_wrd);
  set have;
  w=findw(txt,'CYQXZZZ',' ','E');
  gander=0;
  if w&amp;gt;1 then do;
    prior_wrd=scan(txt,w-1);
    if length(prior_wrd)=6 and notdigit(trim(prior_wrd))=0 then gander=1;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Mar 2019 20:34:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-Based-on-Pattern-Matching/m-p/540201#M148983</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-03-04T20:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting Based on Pattern Matching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-Based-on-Pattern-Matching/m-p/540202#M148984</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;prxmatch("/\b\d{6}\sCYQXZZZ/o", t1.MSG_RAW_TXT) &amp;gt; 0 as GANDER_VOICE&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: the "o" suffix in the pattern tells SAS that the pattern is a constant that should be compiled only once.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 20:35:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-Based-on-Pattern-Matching/m-p/540202#M148984</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-03-04T20:35:17Z</dc:date>
    </item>
  </channel>
</rss>

