<?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: selecting variables based on name prefix and suffix in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/selecting-variables-based-on-name-prefix-and-suffix/m-p/795395#M255129</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select name into :var_list separated by " "
from dictionary.columns
where libname = "WORK" and memname="HAVE"
and (%lowcase(name) substr(name, 1, 4) in ('mon_', 'wed_', 'fri_') AND substr(%lowcase(name), length(name)-3) in ('_07', '_11') )
or %lowcase(name) like 'sat_%_11';
quit;

%put &amp;amp;var_list;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested but something along those lines is what you should aim for.&amp;nbsp;&lt;BR /&gt;If you're doing this in SQL then you may want to change the separate by to have a comma in between the names.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data set names and libraries are stored in upper case letters. Variable names can be mixed case so you may need to account for that more than what I did above.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/217720"&gt;@axescot78&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have dataset with a long list of variables. I am interested in selecting those variables that start with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;mon_&lt;/P&gt;
&lt;P&gt;wed_&lt;/P&gt;
&lt;P&gt;fri_&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and end with:&lt;/P&gt;
&lt;P&gt;_07&lt;/P&gt;
&lt;P&gt;_11&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am also interested in those that start with:&lt;/P&gt;
&lt;P&gt;sat_&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and end with:&lt;/P&gt;
&lt;P&gt;_11&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There could be any character and any number of character in between. How can I select these programmatically?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Feb 2022 00:24:11 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-02-10T00:24:11Z</dc:date>
    <item>
      <title>selecting variables based on name prefix and suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-variables-based-on-name-prefix-and-suffix/m-p/795390#M255126</link>
      <description>&lt;P&gt;I have dataset with a long list of variables. I am interested in selecting those variables that start with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;mon_&lt;/P&gt;
&lt;P&gt;wed_&lt;/P&gt;
&lt;P&gt;fri_&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and end with:&lt;/P&gt;
&lt;P&gt;_07&lt;/P&gt;
&lt;P&gt;_11&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am also interested in those that start with:&lt;/P&gt;
&lt;P&gt;sat_&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and end with:&lt;/P&gt;
&lt;P&gt;_11&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There could be any character and any number of character in between. How can I select these programmatically?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 23:36:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-variables-based-on-name-prefix-and-suffix/m-p/795390#M255126</guid>
      <dc:creator>axescot78</dc:creator>
      <dc:date>2022-02-09T23:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: selecting variables based on name prefix and suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-variables-based-on-name-prefix-and-suffix/m-p/795394#M255128</link>
      <description>&lt;P&gt;Using the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/n02s19q65mw08gn140bwfdh7spx7.htm" target="_blank" rel="noopener"&gt;SAS DICTIONARY tables&lt;/A&gt; is the most flexible way of getting a list of the required columns. The one you want is called COLUMNS:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select name
into :varlist separated by ' '
from dictionary.columns
where libname = 'SASHELP'
and memname = 'CLASS'
;
quit;

%put varlist = &amp;amp;varlist;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 00:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-variables-based-on-name-prefix-and-suffix/m-p/795394#M255128</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-02-10T00:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: selecting variables based on name prefix and suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-variables-based-on-name-prefix-and-suffix/m-p/795395#M255129</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select name into :var_list separated by " "
from dictionary.columns
where libname = "WORK" and memname="HAVE"
and (%lowcase(name) substr(name, 1, 4) in ('mon_', 'wed_', 'fri_') AND substr(%lowcase(name), length(name)-3) in ('_07', '_11') )
or %lowcase(name) like 'sat_%_11';
quit;

%put &amp;amp;var_list;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested but something along those lines is what you should aim for.&amp;nbsp;&lt;BR /&gt;If you're doing this in SQL then you may want to change the separate by to have a comma in between the names.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data set names and libraries are stored in upper case letters. Variable names can be mixed case so you may need to account for that more than what I did above.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/217720"&gt;@axescot78&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have dataset with a long list of variables. I am interested in selecting those variables that start with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;mon_&lt;/P&gt;
&lt;P&gt;wed_&lt;/P&gt;
&lt;P&gt;fri_&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and end with:&lt;/P&gt;
&lt;P&gt;_07&lt;/P&gt;
&lt;P&gt;_11&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am also interested in those that start with:&lt;/P&gt;
&lt;P&gt;sat_&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and end with:&lt;/P&gt;
&lt;P&gt;_11&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There could be any character and any number of character in between. How can I select these programmatically?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 00:24:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-variables-based-on-name-prefix-and-suffix/m-p/795395#M255129</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-02-10T00:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: selecting variables based on name prefix and suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/selecting-variables-based-on-name-prefix-and-suffix/m-p/795397#M255130</link>
      <description>&lt;P&gt;Without knowing where you got those variable names I can't suggest an actual fix. However, you are placing data in the variable names as it appears you have day of the week and possibly a month or day of month value. You will find in the long run that such "names" are very cumbersome to work with and often indicated poor data structure for many analysis, reporting or graphing tasks.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 03:45:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/selecting-variables-based-on-name-prefix-and-suffix/m-p/795397#M255130</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-02-10T03:45:57Z</dc:date>
    </item>
  </channel>
</rss>

