<?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: Extract substring of list using regular expression using a one-line solution and no datastep in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-substring-of-list-using-regular-expression-using-a-one/m-p/849689#M335879</link>
    <description>&lt;P&gt;It is much easier to work with strings in data steps than in macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think this is what you are trying to do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards truncover;
  input varlist $100. ;
  varlist=compbl(varlist);
cards;
_SORT1 RISKFACT _TOGETH _T_1 _T_2 _T_3 _T_4 _MERGE _BIN1 _BIN2
_SORT1 RISKFACT _TOGETH _T_1 _T_2 _T_3 _T_4
_SORT1 RISKFACT _TOGETH _T_1 _T_2 BIN1 _MERGE _T_3 _OTH1 _OTH2 _T_4
;

data want;
  set have;
  droplist = compbl(prxchange('s/_t_\d+//i', -1, varlist));
  keeplist = compbl(prxchange(cats('s/',translate(droplist,'|',' '),'//i'), -1, varlist));
  put (_all_) (=/) //;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;varlist=_SORT1 RISKFACT _TOGETH _T_1 _T_2 _T_3 _T_4 _MERGE _BIN1 _BIN2
droplist=_SORT1 RISKFACT _TOGETH _MERGE _BIN1 _BIN2
keeplist=_T_1 _T_2 _T_3 _T_4



varlist=_SORT1 RISKFACT _TOGETH _T_1 _T_2 _T_3 _T_4
droplist=_SORT1 RISKFACT _TOGETH
keeplist=_T_1 _T_2 _T_3 _T_4



varlist=_SORT1 RISKFACT _TOGETH _T_1 _T_2 BIN1 _MERGE _T_3 _OTH1 _OTH2 _T_4
droplist=_SORT1 RISKFACT _TOGETH BIN1 _MERGE _OTH1 _OTH2
keeplist=_T_1 _T_2 _T_3 _T_4
&lt;/PRE&gt;</description>
    <pubDate>Wed, 14 Dec 2022 16:41:47 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-12-14T16:41:47Z</dc:date>
    <item>
      <title>Extract substring of list using regular expression using a one-line solution and no datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-substring-of-list-using-regular-expression-using-a-one/m-p/849683#M335877</link>
      <description>&lt;P&gt;I have macro variables (see below)&amp;nbsp;that contain the names of variables of a dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;Copy to reproduce example&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _varlist = %str(_SORT1 RISKFACT _TOGETH _T_1 _T_2 _T_3 _T_4 _MERGE _BIN1 _BIN2);
%let _varlist_v2 = %str(_SORT1 RISKFACT _TOGETH _T_1 _T_2 _T_3 _T_4);
%let _varlist_v3 = %str(_SORT1 RISKFACT _TOGETH _T_1 _T_2 BIN1 _MERGE _T_3 _OTH1 _OTH2 _T_4);

data dummy_varlist;
    length _SORT1 RISKFACT _TOGETH _T_1-_T_4 _MERGE _BIN1-_BIN2 $ 20;
    array _chars _SORT1 RISKFACT _TOGETH _T_1-_T_4 _MERGE _BIN1-_BIN2;
    do over _chars;
        call missing (of _chars);
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT size="5"&gt;Task&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;I want to extract the substring&lt;/P&gt;
&lt;P class="lia-align-center"&gt;&lt;STRONG&gt;&lt;FONT color="#800080"&gt;_T_1 _T_2 _T_3 _T_4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;of the above macro variables (&lt;FONT color="#FF6600"&gt;&amp;amp;_varlist&lt;/FONT&gt;,&amp;nbsp;&lt;FONT color="#FF6600"&gt;&amp;amp;_varlist_v2&lt;/FONT&gt; and &lt;FONT color="#FF6600"&gt;&amp;amp;_varlist_v3&lt;/FONT&gt;) using a wildcard/ pattern search.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;Restrictions&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Lets assume I/&lt;FONT color="#3366FF"&gt;we only know the name of the variables we look for&lt;/FONT&gt;, but not anything about position, order or appearance of other variables. Hence we cannot use information of anything other than the provided search string.&lt;/P&gt;
&lt;P&gt;Ideally it should also work for macro variable &lt;FONT color="#FF6600"&gt;&amp;amp;_varlist_v3&lt;/FONT&gt; where the required variables are mixed in-between others.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;Methods/ Howto&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;I do think it should be possible to solve this using an elegant&amp;nbsp;&lt;EM&gt;one-liner&lt;/EM&gt; solution, but I fail to get it right.&lt;/P&gt;
&lt;P&gt;I think one way is to use regular expressions and therefore applying a function of the&amp;nbsp;&lt;STRONG&gt;prx&lt;/STRONG&gt; family:&amp;nbsp;&lt;STRONG&gt;prxchange()&lt;/STRONG&gt; is my best guess. Probably I use the wrong search/replace regular expression.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="5"&gt;One-line solution attempts&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Here are some attempts that failed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _invert = %bquote(%sysfunc(prxchange(%str(s/_t_\d+/$1/i), -1, %bquote(&amp;amp;_varlist))));
/* Gives:
 _SORT1 RISKFACT _TOGETH     _MERGE _BIN1 _BIN2
*/

%let _snippet = %bquote(%sysfunc(prxchange(%str(s/^(.*\w+\b) _t_\d+/$2/i), -1, %bquote(&amp;amp;_varlist))));
/* Gives:
 _MERGE _BIN1 _BIN2
*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT size="5"&gt;Other solution&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Working, but awkward/ over-complicated:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    length varlist $ 200;
    call missing(varlist);
    do _n_ = 1 by 1 until (last);
        set sashelp.vcolumn (where = (libname = %upcase("work") and memname = %upcase("dummy_varlist") and prxmatch("/_t_\d+/i", name))) end = last;
        varlist = ifc(_n_ = 1, name, catx(" ", varlist, name));
    end;
    call symputx("_varlist_out", varlist);      /* assigns the value "_t_1 _t_2 _t_3 _t_4". */
run;
%put &amp;amp;_varlist_out;
/* Gives:
_T_1 _T_2 _T_3 _T_4
*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have any other suggestions (including proc sql, pipe [unix commands]) I am happy to learn them.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 16:14:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-substring-of-list-using-regular-expression-using-a-one/m-p/849683#M335877</guid>
      <dc:creator>left</dc:creator>
      <dc:date>2022-12-14T16:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: Extract substring of list using regular expression using a one-line solution and no datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-substring-of-list-using-regular-expression-using-a-one/m-p/849689#M335879</link>
      <description>&lt;P&gt;It is much easier to work with strings in data steps than in macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think this is what you are trying to do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards truncover;
  input varlist $100. ;
  varlist=compbl(varlist);
cards;
_SORT1 RISKFACT _TOGETH _T_1 _T_2 _T_3 _T_4 _MERGE _BIN1 _BIN2
_SORT1 RISKFACT _TOGETH _T_1 _T_2 _T_3 _T_4
_SORT1 RISKFACT _TOGETH _T_1 _T_2 BIN1 _MERGE _T_3 _OTH1 _OTH2 _T_4
;

data want;
  set have;
  droplist = compbl(prxchange('s/_t_\d+//i', -1, varlist));
  keeplist = compbl(prxchange(cats('s/',translate(droplist,'|',' '),'//i'), -1, varlist));
  put (_all_) (=/) //;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;varlist=_SORT1 RISKFACT _TOGETH _T_1 _T_2 _T_3 _T_4 _MERGE _BIN1 _BIN2
droplist=_SORT1 RISKFACT _TOGETH _MERGE _BIN1 _BIN2
keeplist=_T_1 _T_2 _T_3 _T_4



varlist=_SORT1 RISKFACT _TOGETH _T_1 _T_2 _T_3 _T_4
droplist=_SORT1 RISKFACT _TOGETH
keeplist=_T_1 _T_2 _T_3 _T_4



varlist=_SORT1 RISKFACT _TOGETH _T_1 _T_2 BIN1 _MERGE _T_3 _OTH1 _OTH2 _T_4
droplist=_SORT1 RISKFACT _TOGETH BIN1 _MERGE _OTH1 _OTH2
keeplist=_T_1 _T_2 _T_3 _T_4
&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Dec 2022 16:41:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-substring-of-list-using-regular-expression-using-a-one/m-p/849689#M335879</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-14T16:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: Extract substring of list using regular expression using a one-line solution and no datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-substring-of-list-using-regular-expression-using-a-one/m-p/849693#M335882</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thank you for your quick reply!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think I have not mentioned why I insisted on regular expressions in this question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In cases like the above I don't know in advance how many variables I have and hence cannot provide a fixed string in advance.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do &lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;only know the pattern&lt;/FONT&gt;&lt;/STRONG&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the example above I could also have variable names like&lt;/P&gt;
&lt;P class="lia-align-center"&gt;&lt;STRONG&gt;&lt;FONT color="#800080"&gt;_T_1 _T_2 _T_3 _T_4 _T_5&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;[...]&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#800080"&gt;_T_87&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;[...]&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#800080"&gt;_T_102&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I am looking for a dynamic solution regarding the regular expression pattern.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 17:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-substring-of-list-using-regular-expression-using-a-one/m-p/849693#M335882</guid>
      <dc:creator>left</dc:creator>
      <dc:date>2022-12-14T17:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Extract substring of list using regular expression using a one-line solution and no datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-substring-of-list-using-regular-expression-using-a-one/m-p/849699#M335883</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/315410"&gt;@left&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thank you for your quick reply!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think I have not mentioned why I insisted on regular expressions in this question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In cases like the above I don't know in advance how many variables I have and hence cannot provide a fixed string in advance.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do &lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;only know the pattern&lt;/FONT&gt;&lt;/STRONG&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the example above I could also have variable names like&lt;/P&gt;
&lt;P class="lia-align-center"&gt;&lt;STRONG&gt;&lt;FONT color="#800080"&gt;_T_1 _T_2 _T_3 _T_4 _T_5&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;[...]&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#800080"&gt;_T_87&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;[...]&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#800080"&gt;_T_102&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I am looking for a dynamic solution regarding the regular expression pattern.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Huh????&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code I posted is using regular expressions and as it demonstrates works for all of the examples you provided.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Works pretty well for the new list also:&lt;/P&gt;
&lt;PRE&gt;varlist=_T_1 _T_2 _T_3 _T_4 _T_5 [...] _T_87 [...] _T_102
droplist=[...] [...]
keeplist=_T_1 _T_2 _T_3 _T_4 _T_5 [] _T_87 [] _T_102
&lt;/PRE&gt;
&lt;P&gt;I suspect the periods confused RegEx.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you saying the pattern is not underscore followed by T followed by underscore followed by one or more digits?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 17:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-substring-of-list-using-regular-expression-using-a-one/m-p/849699#M335883</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-14T17:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: Extract substring of list using regular expression using a one-line solution and no datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-substring-of-list-using-regular-expression-using-a-one/m-p/849702#M335885</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/315410"&gt;@left&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thank you for your quick reply!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think I have not mentioned why I insisted on regular expressions in this question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In cases like the above I don't know in advance how many variables I have and hence cannot provide a fixed string in advance.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do &lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;only know the pattern&lt;/FONT&gt;&lt;/STRONG&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the example above I could also have variable names like&lt;/P&gt;
&lt;P class="lia-align-center"&gt;&lt;STRONG&gt;&lt;FONT color="#800080"&gt;_T_1 _T_2 _T_3 _T_4 _T_5&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;[...]&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#800080"&gt;_T_87&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;[...]&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#800080"&gt;_T_102&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I am looking for a dynamic solution regarding the regular expression pattern.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Huh????&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code I posted is using regular expressions and as it demonstrates works for all of the examples you provided.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Works for the new list also:&lt;/P&gt;
&lt;PRE&gt;varlist=_T_1 _T_2 _T_3 _T_4 _T_5 [...] _T_87 [...] _T_102
droplist=[...] [...]
keeplist=_T_1 _T_2 _T_3 _T_4 _T_5 [] _T_87 [] _T_102
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you saying the pattern is not underscore followed by T followed by underscore followed by one or more digits?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the pattern is correct as specified - your code is also doing the job just perfectly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When reading your solution I overlooked the first part where you derived the solution and just focused on the 2nd box with the results thinking you wanted me to use a fixed string &lt;FONT color="#800080"&gt;_T_1 _T_2&amp;nbsp;_T_3 _T_4&lt;/FONT&gt; only. Excuse me for this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However I wonder if I can get a result for a single macro variable on demand using only&amp;nbsp;&lt;STRONG&gt;a single line of code&lt;/STRONG&gt;, e.g. with this kind of pseudocode&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let droplist = %sysfunc(compbl(%sysfunc(prxchange(s/_t_\d+//i, -1, &amp;amp;_varlist));
%let keeplist = %sysfunc(compbl(%sysfunc(prxchange(cats(s/,translate(&amp;amp;droplist,|, ),//i), -1, &amp;amp;_varlist));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but in one line only (or max. 2).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe using a pipe (applying some unix command like&amp;nbsp;&lt;EM&gt;sed&lt;/EM&gt;,&amp;nbsp;&lt;EM&gt;awk&lt;/EM&gt;) if it is difficult in SAS directly without using a datastep.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, if this would just not make sense, then your solution will become the one to go for.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 17:41:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-substring-of-list-using-regular-expression-using-a-one/m-p/849702#M335885</guid>
      <dc:creator>left</dc:creator>
      <dc:date>2022-12-14T17:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: Extract substring of list using regular expression using a one-line solution and no datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-substring-of-list-using-regular-expression-using-a-one/m-p/849706#M335888</link>
      <description>&lt;P&gt;The same way you can convert these statements:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;y = x + 5;
z = sqrt(y) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To one statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;z = sqrt(x + 5);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Dec 2022 17:59:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-substring-of-list-using-regular-expression-using-a-one/m-p/849706#M335888</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-14T17:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Extract substring of list using regular expression using a one-line solution and no datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-substring-of-list-using-regular-expression-using-a-one/m-p/849709#M335890</link>
      <description>&lt;P&gt;But why would you want to generate code you could never hope to be able to maintain?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list=_SORT1 RISKFACT _TOGETH _T_1 _T_2 BIN1 _MERGE _T_3 _OTH1 _OTH2 _T_4;
%let keeplist=%sysfunc(compbl(%sysfunc(prxchange(s/%sysfunc(translate(%sysfunc(compbl(%sysfunc(prxchange(s/_t_\d+//i,-1,&amp;amp;list)))),|,%str( )))//i,-1,&amp;amp;list))));
%put &amp;amp;=keeplist;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;392  %let list=_SORT1 RISKFACT _TOGETH _T_1 _T_2 BIN1 _MERGE _T_3 _OTH1 _OTH2 _T_4;
393  %let
393! keeplist=%sysfunc(compbl(%sysfunc(prxchange(s/%sysfunc(translate(%sysfunc(compbl(%sysfunc(prxchange(s/_t_\d+//i,-1,&amp;amp;list)))),|,
393! %str( )))//i,-1,&amp;amp;list))));
394  %put &amp;amp;=keeplist;
KEEPLIST=_T_1 _T_2 _T_3 _T_4
&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Dec 2022 18:10:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-substring-of-list-using-regular-expression-using-a-one/m-p/849709#M335890</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-14T18:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: Extract substring of list using regular expression using a one-line solution and no datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-substring-of-list-using-regular-expression-using-a-one/m-p/849826#M335928</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;But why would you want to generate code you could never hope to be able to maintain?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;True, Tom.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having code in that form in one line is hard to read, maintain and debug.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was hoping this can be achieved by a single function call of&amp;nbsp;&lt;EM&gt;prxchange()&lt;/EM&gt; only. That would still be feasable if wrapped by&amp;nbsp;&lt;EM&gt;%sysfunc()&lt;/EM&gt; outside of a data step.&lt;/P&gt;
&lt;P&gt;All in all - your first answer is the most appropriate solution then.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you indeed that you have gone that extra mile to explain why a&amp;nbsp;&lt;EM&gt;one-liner&lt;/EM&gt; is not the best solution.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 10:16:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-substring-of-list-using-regular-expression-using-a-one/m-p/849826#M335928</guid>
      <dc:creator>left</dc:creator>
      <dc:date>2022-12-15T10:16:25Z</dc:date>
    </item>
  </channel>
</rss>

