<?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: Drop multiple variables with different prefix in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Drop-multiple-variables-with-different-prefix/m-p/681137#M205992</link>
    <description>&lt;P&gt;Unfortunately the above answer doesn't take care of "XY" embedded in the middle of a variable.&amp;nbsp; However, since the "XY's" all are prefixed with a "W", you could code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	Moi.Names;
	DROP  WXY:;	
    DROP  AA01:;
    DROP  AA02:;
    DROP  AA03:;
    DROP  LICAT:;
	SET	Moi.INDUSTRY;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which would give you:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Wildcard_Drop_Results_2020-09-02_12-04-28.jpg" style="width: 501px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/48927i0A81E6F58BF27207/image-size/large?v=v2&amp;amp;px=999" role="button" title="Wildcard_Drop_Results_2020-09-02_12-04-28.jpg" alt="Wildcard_Drop_Results_2020-09-02_12-04-28.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
    <pubDate>Wed, 02 Sep 2020 19:06:02 GMT</pubDate>
    <dc:creator>jimbarbour</dc:creator>
    <dc:date>2020-09-02T19:06:02Z</dc:date>
    <item>
      <title>Drop multiple variables with different prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-multiple-variables-with-different-prefix/m-p/681120#M205978</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;&lt;P&gt;I want to drop some variables from a dataset with over 200 variables. The variable names are unique but are grouped using a common prefix/characters.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following variables table is a sample obtained using the code below. For example, I would like to drop the range of variables starting with AA01 -&amp;nbsp;AA03, variables that start with 'LICAT' and variables containing 'XY' and 'BC'. Thank you.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=moi.industry out=moi.names(keep=name) noprint ; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;NAME&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AA08&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AA01Z08&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AA01Y08&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AA02Z08&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AA02Y08&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AA03Z08&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AA03Y08&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AA04Z08&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AA04Y08&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AA05Z08&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AA05Y08&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;BBCY08&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;BBCZ08&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;LICATY08&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;LICATN08&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;WXY01Y08&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;WXY01X08&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 02 Sep 2020 18:11:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-multiple-variables-with-different-prefix/m-p/681120#M205978</guid>
      <dc:creator>michokwu</dc:creator>
      <dc:date>2020-09-02T18:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: Drop multiple variables with different prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-multiple-variables-with-different-prefix/m-p/681121#M205979</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
    select name into :names separated by ' ' from moi.names 
      where name eqt 'LICAT' or name?'XY' or name?'BC';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then in a data step&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;drop &amp;amp;names;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Sep 2020 18:13:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-multiple-variables-with-different-prefix/m-p/681121#M205979</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-02T18:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: Drop multiple variables with different prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-multiple-variables-with-different-prefix/m-p/681132#M205988</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; Thank you. It works, except for the range&amp;nbsp;&lt;SPAN&gt;AA01 -&amp;nbsp;AA03.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 18:54:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-multiple-variables-with-different-prefix/m-p/681132#M205988</guid>
      <dc:creator>michokwu</dc:creator>
      <dc:date>2020-09-02T18:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: Drop multiple variables with different prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-multiple-variables-with-different-prefix/m-p/681133#M205989</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/255120"&gt;@michokwu&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For prefixed variables, it's very easy.&amp;nbsp; You can use the colon as a wild card.&amp;nbsp; For example in the data step below, all variables starting with&amp;nbsp;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;AA01" -&amp;nbsp;"AA03" and "LICAT."&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA  moi.names;
    DROP  AA01:;
    DROP  AA02:;
    DROP  AA03:;
    DROP  LICAT:;
    SET  moi.industry;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Jim&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 18:55:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-multiple-variables-with-different-prefix/m-p/681133#M205989</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-02T18:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: Drop multiple variables with different prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-multiple-variables-with-different-prefix/m-p/681134#M205990</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/255120"&gt;@michokwu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; Thank you. It works, except for the range&amp;nbsp;&lt;SPAN&gt;AA01 -&amp;nbsp;AA03.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You have the change the WHERE clause in PROC SQL to select variables whose names begin with AA01-AA03. Since I showed you how to delete names that begin with LICAT, I leave deleting names that begin with AA01-AA03 up to you as a homework assignment.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 19:09:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-multiple-variables-with-different-prefix/m-p/681134#M205990</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-02T19:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: Drop multiple variables with different prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-multiple-variables-with-different-prefix/m-p/681137#M205992</link>
      <description>&lt;P&gt;Unfortunately the above answer doesn't take care of "XY" embedded in the middle of a variable.&amp;nbsp; However, since the "XY's" all are prefixed with a "W", you could code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	Moi.Names;
	DROP  WXY:;	
    DROP  AA01:;
    DROP  AA02:;
    DROP  AA03:;
    DROP  LICAT:;
	SET	Moi.INDUSTRY;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which would give you:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Wildcard_Drop_Results_2020-09-02_12-04-28.jpg" style="width: 501px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/48927i0A81E6F58BF27207/image-size/large?v=v2&amp;amp;px=999" role="button" title="Wildcard_Drop_Results_2020-09-02_12-04-28.jpg" alt="Wildcard_Drop_Results_2020-09-02_12-04-28.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 19:06:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-multiple-variables-with-different-prefix/m-p/681137#M205992</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-02T19:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: Drop multiple variables with different prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-multiple-variables-with-different-prefix/m-p/681172#M206013</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp; Thanks. Surprisingly, it works for me. I don't&amp;nbsp; really want to write out all the prefixes, that's why I'm trying to use a range of variables&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 22:34:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-multiple-variables-with-different-prefix/m-p/681172#M206013</guid>
      <dc:creator>michokwu</dc:creator>
      <dc:date>2020-09-02T22:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: Drop multiple variables with different prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-multiple-variables-with-different-prefix/m-p/681174#M206014</link>
      <description>&lt;P&gt;I understand. In that case, it's better to go with what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; suggested.&amp;nbsp; Would you like help with that or do understand what he was suggesting?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, save the colon wildcard in the back of your mind somewhere.&amp;nbsp; It is a useful technique.&amp;nbsp; If you prefix all your work variables with an underscore, you can code a single drop statement such that no work variables wind up in your Production data.&amp;nbsp; For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA Prod.Very_Important_Data;
    DROP  _:;
    SET Input.Source_Data;
     _Daily_Amount = Annual_Amount / 365;
    _Standardized_Quarter = (30 * 3);
     Quarterly_Amount = _Daily_Amount * _Standardized_Quarter;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above example is a bit contrived, but in this case&amp;nbsp;_Daily_Amount and _Standardized_Quarter are removed from the final results because of the Drop statement.&amp;nbsp; In a program with dozens of intermediate or work variables, the colon modifier is very handy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 22:56:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-multiple-variables-with-different-prefix/m-p/681174#M206014</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-02T22:56:21Z</dc:date>
    </item>
  </channel>
</rss>

