<?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: Delete all Columns that contain a certain String in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-Columns-that-contain-a-certain-String/m-p/346163#M79776</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;I don't really have control of the naming conventions. The data I'm working with deals with human subjects so I can't go into too much detail about it, however the names basically are like what I mentioned XXXXXX and XXXXXXX_HET for everything. I was hoping I could delete all the columns with _HET first, then rename the remaining columns to XX1, XX2, XX3, etc.... so I can do analysis easily just by doing a loop. I am just having trouble thinking about how I can reference the column names or maybe their positions because their names are very different and it would be troublesome to do "rename XXXXXX = XX1" for every single one of them.&lt;/P&gt;</description>
    <pubDate>Fri, 31 Mar 2017 15:00:40 GMT</pubDate>
    <dc:creator>Leon27607</dc:creator>
    <dc:date>2017-03-31T15:00:40Z</dc:date>
    <item>
      <title>Delete all Columns that contain a certain String</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-Columns-that-contain-a-certain-String/m-p/346141#M79763</link>
      <description>&lt;P&gt;Is there some way to reference column names? I mean deleting observations in a ROW is easy but is there a way to delete COLUMNS that are named a certain way?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example of what my data might look like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A &amp;nbsp; &amp;nbsp;A_HET &amp;nbsp;B &amp;nbsp; B_HET &amp;nbsp;C &amp;nbsp; C_HET &amp;nbsp;D &amp;nbsp; D_HET &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;41234 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;12351 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;41256 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;54432 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;etc...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I basically want to delete ALL columns with "HET" in them. I know for rows you could simply write "If colname := "HET" then delete" but how do I do this the "other" way around?&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 13:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-all-Columns-that-contain-a-certain-String/m-p/346141#M79763</guid>
      <dc:creator>Leon27607</dc:creator>
      <dc:date>2017-03-31T13:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all Columns that contain a certain String</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-Columns-that-contain-a-certain-String/m-p/346144#M79766</link>
      <description>&lt;P&gt;I would use metadata to create a macro variable to use in a drop statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  SELECT name INTO :dropMe SEPARATED BY ' '
  FROM sashelp.vcolumn
  WHERE libname = 'YOURLIB' AND
                memname = 'HAVE' AND
                prxmatch('/het$/i', strip(name)) &amp;gt; 0;
quit;

data want;
  set have;
  drop &amp;amp;dropMe;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 Mar 2017 13:55:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-all-Columns-that-contain-a-certain-String/m-p/346144#M79766</guid>
      <dc:creator>collinelliot</dc:creator>
      <dc:date>2017-03-31T13:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all Columns that contain a certain String</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-Columns-that-contain-a-certain-String/m-p/346156#M79772</link>
      <description>&lt;P&gt;If you have control of your naming conventions, if you name the variables with a consistent prefix this can be very simple. Unfortunately it doesn't work for suffixes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Drop het_: ;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 14:18:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-all-Columns-that-contain-a-certain-String/m-p/346156#M79772</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-31T14:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all Columns that contain a certain String</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-Columns-that-contain-a-certain-String/m-p/346163#M79776</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;I don't really have control of the naming conventions. The data I'm working with deals with human subjects so I can't go into too much detail about it, however the names basically are like what I mentioned XXXXXX and XXXXXXX_HET for everything. I was hoping I could delete all the columns with _HET first, then rename the remaining columns to XX1, XX2, XX3, etc.... so I can do analysis easily just by doing a loop. I am just having trouble thinking about how I can reference the column names or maybe their positions because their names are very different and it would be troublesome to do "rename XXXXXX = XX1" for every single one of them.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2017 15:00:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-all-Columns-that-contain-a-certain-String/m-p/346163#M79776</guid>
      <dc:creator>Leon27607</dc:creator>
      <dc:date>2017-03-31T15:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all Columns that contain a certain String</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-Columns-that-contain-a-certain-String/m-p/346169#M79778</link>
      <description>&lt;P&gt;Renaming all your variables does not necessarily have to be that much of a hassle. The following code gives an example of how you could use metadata to flip "_het" to "het_" for many variables. It would have to adapted to the particulars of your data, probably, but this should give you an idea.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    retain a_het xx_het zdfe_het b_het a234_het 0;
    x = 1;
run;

proc sql;
    SELECT catx('=', name, prxchange('s/(\w{1,28})(_)(het)/\3\2\1/i', -1, strip(name))) INTO :renameMe SEPARATED BY ' '
    FROM sashelp.vcolumn
    WHERE libname = 'WORK' AND
          memname = 'HAVE' AND
          prxmatch('/_het$/i', strip(name)) &amp;gt; 0;
quit;

data want;
    set have;
    rename &amp;amp;renameMe;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 Mar 2017 14:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-all-Columns-that-contain-a-certain-String/m-p/346169#M79778</guid>
      <dc:creator>collinelliot</dc:creator>
      <dc:date>2017-03-31T14:55:52Z</dc:date>
    </item>
  </channel>
</rss>

