<?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: Pattern matching issue in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-issue/m-p/887491#M350633</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t_cdr_202212_2;
input name $;
datalines;
aa
bb
;
run;

data t_cdr_202212_10;
input name $;
datalines;
aa
bb
;
run;

data t_cdr_202212_10_BKP;
input name $;
datalines;
aa
bb
;
run;

data t_cdr_202212_HVB_10_BKP;
input name $;
datalines;
aa
bb
;
run;


%macro test;
  /* Create table_list using DICTIONARY.TABLES */
%let YYMMM = 202212;


   PROC SQL;
    CREATE TABLE table_list AS 
    SELECT memname 
    FROM dictionary.tables
    WHERE libname = 'WORK'
      AND memname like "T_CDR_&amp;amp;YYMMM._%"
     ;

QUIT;
  
%mend test;
%test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am providing sample code..&lt;/P&gt;</description>
    <pubDate>Wed, 02 Aug 2023 14:05:47 GMT</pubDate>
    <dc:creator>Sathya3</dc:creator>
    <dc:date>2023-08-02T14:05:47Z</dc:date>
    <item>
      <title>Pattern matching issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-issue/m-p/887487#M350629</link>
      <description>&lt;P&gt;%let YYMMM=202303;&lt;/P&gt;
&lt;P&gt;Proc sql;&lt;/P&gt;
&lt;P&gt;create table table_list as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select memname from dictionary.tables&lt;/P&gt;
&lt;P&gt;where libname='HVGRP'&lt;/P&gt;
&lt;P&gt;and memname like "T_cdr_&amp;amp;yyyymm_%"&lt;/P&gt;
&lt;P&gt;order by input(substr(memname,length("T_CDR_&amp;amp;YYYYMM._")+1),8.);&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want memname to adhere to below specifications:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;To correctly match values like "T_CDR_202303_1", "T_CDR_202303_2" and so on&amp;nbsp; "T_CDR_202303_n", ( where n is not a fixed integer&amp;nbsp; &amp;nbsp;and it starts from 1 )&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;It should not match patterns other than above .It should exclude patterns for eg: "T_CDR_202303_SVB_0712" ,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;"T_CDR_202303_1_BKP"&lt;/SPAN&gt;&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>Wed, 02 Aug 2023 13:34:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-issue/m-p/887487#M350629</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2023-08-02T13:34:27Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern matching issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-issue/m-p/887489#M350631</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;dictionnary table entries are upper case so you probably only need to modify&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; memname like "T_cdr_&amp;amp;yyyymm_%"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; memname like "T_CDR_&amp;amp;yyyymm._%"&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Aug 2023 13:47:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-issue/m-p/887489#M350631</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2023-08-02T13:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern matching issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-issue/m-p/887490#M350632</link>
      <description>&lt;P&gt;That is not the issue..&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 14:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-issue/m-p/887490#M350632</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2023-08-02T14:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern matching issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-issue/m-p/887491#M350633</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t_cdr_202212_2;
input name $;
datalines;
aa
bb
;
run;

data t_cdr_202212_10;
input name $;
datalines;
aa
bb
;
run;

data t_cdr_202212_10_BKP;
input name $;
datalines;
aa
bb
;
run;

data t_cdr_202212_HVB_10_BKP;
input name $;
datalines;
aa
bb
;
run;


%macro test;
  /* Create table_list using DICTIONARY.TABLES */
%let YYMMM = 202212;


   PROC SQL;
    CREATE TABLE table_list AS 
    SELECT memname 
    FROM dictionary.tables
    WHERE libname = 'WORK'
      AND memname like "T_CDR_&amp;amp;YYMMM._%"
     ;

QUIT;
  
%mend test;
%test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am providing sample code..&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 14:05:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-issue/m-p/887491#M350633</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2023-08-02T14:05:47Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern matching issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-issue/m-p/887502#M350636</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442456"&gt;@Sathya3&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;It should not match patterns other than above .It should exclude patterns for eg: "T_CDR_202303_SVB_0712" ,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;"T_CDR_202303_1_BKP"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What makes you think that? There is nothing in the code&lt;/P&gt;
&lt;PRE&gt; memname like "T_CDR_&amp;amp;yyyymm_%"&lt;/PRE&gt;
&lt;P&gt;which matches anything starting with those. Or are you requesting such?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;and input(scan(memname,4,'_'),f4.)&amp;gt;0&lt;/PRE&gt;
&lt;P&gt;perhaps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or look at the PRX functions that you can specify that digits appear in specific places in the pattern.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 14:50:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-issue/m-p/887502#M350636</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-02T14:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern matching issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-issue/m-p/887526#M350642</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442456"&gt;@Sathya3&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would need to use an &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/n1ege2983n6h0vn1s1uj1459phr9.htm#n083k66m7y2r4an158a3lhd4t96t" target="_blank" rel="noopener"&gt;escape character&lt;/A&gt; to match a literal underscore with the LIKE operator. But the condition "only digits after the underscore following the date string" exceeds the capabilities of the LIKE operator. Therefore, I suggest a condition using a Perl regular expression instead of the LIKE condition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;prxmatch("/^T_CDR_&amp;amp;YYMMM._\d+$/",trim(memname))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;where "&lt;FONT face="courier new,courier"&gt;\d+$&lt;/FONT&gt;" matches one or more digits at the end of &lt;FONT face="courier new,courier"&gt;trim(memname)&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: ... and the "^" sign matches the beginning of the string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit 2:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442456"&gt;@Sathya3&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;To correctly match values like "T_CDR_202303_1", "T_CDR_202303_2" and so on&amp;nbsp; "T_CDR_202303_n", ( where n is not a fixed integer&amp;nbsp; &amp;nbsp;and it starts from 1 )&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;It should not match patterns other than above .&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If names with leading zeros in the number at the end must be excluded, use this modification of the regex:&lt;/P&gt;
&lt;PRE&gt;prxmatch("/^T_CDR_&amp;amp;YYMMM._&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;[1-9]&lt;/STRONG&gt;&lt;/FONT&gt;\d&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;*&lt;/STRONG&gt;&lt;/FONT&gt;$/",trim(memname))&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 16:35:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-issue/m-p/887526#M350642</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-08-02T16:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern matching issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-issue/m-p/887531#M350643</link>
      <description>&lt;P&gt;So you want to exclude those that do not have a numeric suffix?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to try check if a string of characters is number is to try to convert it to a number using the INPUT() function.&amp;nbsp; Perhaps you could just simplify to checking the characters after the last underscore.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let YYMMM=202303;
proc sql;
create table table_list as 
  select memname
       , input(scan(memname,-1,'_'),?32.) as suffix
  from dictionary.tables
  where libname='HVGRP'
    and memname like "T^_CDR^_&amp;amp;yyyymm.^_%" escape '^'
    and not missing(calculated suffix)
  order by suffix
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 19:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-issue/m-p/887531#M350643</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-02T19:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern matching issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-issue/m-p/887620#M350671</link>
      <description>&lt;P&gt;I see, you want also to exclude the other terms.&lt;/P&gt;
&lt;P&gt;Then a regular expression should do the job:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where libname='HVGRP'
and prxmatch("/^T_CDR_&amp;amp;YYMMM._\d+$/",strip(memname))&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Aug 2023 05:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pattern-matching-issue/m-p/887620#M350671</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2023-08-03T05:44:06Z</dc:date>
    </item>
  </channel>
</rss>

