<?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 Subset data by column, using wildcards? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Subset-data-by-column-using-wildcards/m-p/822330#M324719</link>
    <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know that we can use the LIKE operator to filter rows of data; below are my notes on this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LIKE operator for pattern matching&lt;/P&gt;
&lt;P&gt;WHERE &lt;I&gt;col-name&lt;/I&gt; LIKE "&lt;I&gt;value&lt;/I&gt;";&lt;/P&gt;
&lt;P&gt;% is a wild card for any number of characters&lt;/P&gt;
&lt;P&gt;_ is a wild card for a single character&lt;/P&gt;
&lt;P&gt;*A wild card is a character that can be substituted for zero or more characters in a string&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;WHERE City LIKE "New%"; will return values like New York, Newport, New&lt;/LI&gt;
&lt;LI&gt;WHERE City LIKE "Sant_&amp;nbsp; %"; will return values like Santa Clara, Santo Domingo&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;STRONG&gt;My question is, is it possible to apply this same logic to subset data by column names?&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More specifically, I have a table with over 100 columns; I want to create a new table that includes only the columns related to Math. Instead of copy/paste or listing all the columns with the word "Math"&amp;nbsp; in the name, can I apply the LIKE operator using the wildcards to create a table including all columns whose name contains the word "Math"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Moreover, would this subsetting need to happen in a DATA step or PROC SQL?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA want; SET have; WHERE *column name; LIKE "%math%"; RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SQL; CREATE TABLE want AS&lt;/P&gt;
&lt;P&gt;SELECT *column name LIKE '%math'; FROM have;&lt;/P&gt;
&lt;P&gt;QUIT;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Jul 2022 18:18:33 GMT</pubDate>
    <dc:creator>tennytivvytutu</dc:creator>
    <dc:date>2022-07-08T18:18:33Z</dc:date>
    <item>
      <title>Subset data by column, using wildcards?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-data-by-column-using-wildcards/m-p/822330#M324719</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know that we can use the LIKE operator to filter rows of data; below are my notes on this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LIKE operator for pattern matching&lt;/P&gt;
&lt;P&gt;WHERE &lt;I&gt;col-name&lt;/I&gt; LIKE "&lt;I&gt;value&lt;/I&gt;";&lt;/P&gt;
&lt;P&gt;% is a wild card for any number of characters&lt;/P&gt;
&lt;P&gt;_ is a wild card for a single character&lt;/P&gt;
&lt;P&gt;*A wild card is a character that can be substituted for zero or more characters in a string&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;WHERE City LIKE "New%"; will return values like New York, Newport, New&lt;/LI&gt;
&lt;LI&gt;WHERE City LIKE "Sant_&amp;nbsp; %"; will return values like Santa Clara, Santo Domingo&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;STRONG&gt;My question is, is it possible to apply this same logic to subset data by column names?&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More specifically, I have a table with over 100 columns; I want to create a new table that includes only the columns related to Math. Instead of copy/paste or listing all the columns with the word "Math"&amp;nbsp; in the name, can I apply the LIKE operator using the wildcards to create a table including all columns whose name contains the word "Math"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Moreover, would this subsetting need to happen in a DATA step or PROC SQL?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA want; SET have; WHERE *column name; LIKE "%math%"; RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SQL; CREATE TABLE want AS&lt;/P&gt;
&lt;P&gt;SELECT *column name LIKE '%math'; FROM have;&lt;/P&gt;
&lt;P&gt;QUIT;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 18:18:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-data-by-column-using-wildcards/m-p/822330#M324719</guid>
      <dc:creator>tennytivvytutu</dc:creator>
      <dc:date>2022-07-08T18:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: Subset data by column, using wildcards?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-data-by-column-using-wildcards/m-p/822350#M324729</link>
      <description>&lt;P&gt;Use the dictionary tables, like here :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET olnames=;
PROC SQL noprint;
 select name into :olnames separated by ' '
 from dictionary.columns
 where libname='SASHELP' and memname='HEART' and name LIKE "%ol%";
QUIT;
%PUT &amp;amp;=olnames;

data work.have; set sashelp.heart(keep=&amp;amp;olnames.); run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 19:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-data-by-column-using-wildcards/m-p/822350#M324729</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2022-07-08T19:39:54Z</dc:date>
    </item>
  </channel>
</rss>

