<?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 Reg: Like in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reg-Like/m-p/48548#M10027</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; the comparison&amp;nbsp; if id=: 'na_'&amp;nbsp; (using the =: operator)&amp;nbsp; will find those ID beginning 'na_' and reject ID= 'na-...' but it is not the same as the LIKE operator&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;'=:' compares the shorter of the two lengths so ID='n' would also satisfy the test ID =: 'na_' &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To select only ID which begin 'na_' you could test just the first 3 characters with&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; substr( id, 1,3 ) = 'na_' &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;by the way, the LIKE operator treats '_' as a special indicator that any character must be present &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; name like &lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: purple; font-size: 9pt;"&gt;'Ja_e__'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; extracts 3 rows from sashelp.class - names Jane, James and Janet. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So some extra care is needed when _ needs to be treated as _ in a LIKE clause.&lt;/P&gt;&lt;P&gt;Check out ESCAPE in the "Syntax of WHERE Expression" at&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000999255.htm"&gt;http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000999255.htm&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 16 Nov 2011 11:13:08 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2011-11-16T11:13:08Z</dc:date>
    <item>
      <title>Reg: Like</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reg-Like/m-p/48547#M10026</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Data l;&lt;BR /&gt;input id$;&lt;BR /&gt;cards;&lt;BR /&gt;na_1&lt;BR /&gt;ra_1&lt;BR /&gt;na_2&lt;BR /&gt;na_*&lt;BR /&gt;gb_p&lt;BR /&gt;na_u&lt;BR /&gt;lo_*&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data l2;&lt;BR /&gt;set l;&lt;BR /&gt;/*if id like 'na_%' then p=1;*/&lt;BR /&gt;where id like 'na_%' ;&lt;BR /&gt;run;&lt;BR /&gt;proc print;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i want if na_ like then to create new variable new_id=1&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2011 09:42:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reg-Like/m-p/48547#M10026</guid>
      <dc:creator>R_Win</dc:creator>
      <dc:date>2011-11-16T09:42:21Z</dc:date>
    </item>
    <item>
      <title>Reg: Like</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reg-Like/m-p/48548#M10027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; the comparison&amp;nbsp; if id=: 'na_'&amp;nbsp; (using the =: operator)&amp;nbsp; will find those ID beginning 'na_' and reject ID= 'na-...' but it is not the same as the LIKE operator&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;'=:' compares the shorter of the two lengths so ID='n' would also satisfy the test ID =: 'na_' &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To select only ID which begin 'na_' you could test just the first 3 characters with&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; substr( id, 1,3 ) = 'na_' &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;by the way, the LIKE operator treats '_' as a special indicator that any character must be present &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 9pt;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 9pt;"&gt; name like &lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: purple; font-size: 9pt;"&gt;'Ja_e__'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; extracts 3 rows from sashelp.class - names Jane, James and Janet. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So some extra care is needed when _ needs to be treated as _ in a LIKE clause.&lt;/P&gt;&lt;P&gt;Check out ESCAPE in the "Syntax of WHERE Expression" at&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000999255.htm"&gt;http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000999255.htm&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2011 11:13:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reg-Like/m-p/48548#M10027</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-11-16T11:13:08Z</dc:date>
    </item>
    <item>
      <title>Reg: Like</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reg-Like/m-p/48549#M10028</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can't use the LIKE operator in this context (this operator is only for use in WHERE statements) - but you CAN use a PERL regular expression and the PRXMATCH function to accomplish the same thing:&lt;/P&gt;&lt;PRE&gt;data l2;
&amp;nbsp;&amp;nbsp; set l;
&amp;nbsp;&amp;nbsp; if prxmatch('/na_\w*/',id) then p=1;
run;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Nov 2011 04:00:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reg-Like/m-p/48549#M10028</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2011-11-24T04:00:40Z</dc:date>
    </item>
    <item>
      <title>Reg: Like</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reg-Like/m-p/48550#M10029</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;Data l;
input id$;
cards;
na_1
ra_1
na_2
na_*
gb_p
na_u
lo_*
run;

 

data l2;
set l;
if lowcase(left(id)) eq: 'na_' then p=1;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Nov 2011 05:51:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reg-Like/m-p/48550#M10029</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-11-24T05:51:54Z</dc:date>
    </item>
  </channel>
</rss>

