<?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 columns whose name contains a certain string (macro) in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Delete-columns-whose-name-contains-a-certain-string-macro/m-p/331001#M21960</link>
    <description>&lt;P&gt;Hey it works for columns names like: vector_4, vectorETC.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would you kindly provide a solution for names like ETC_vector_ETC, ETC_vector?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Feb 2017 22:01:48 GMT</pubDate>
    <dc:creator>ayin</dc:creator>
    <dc:date>2017-02-08T22:01:48Z</dc:date>
    <item>
      <title>Delete columns whose name contains a certain string (macro)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Delete-columns-whose-name-contains-a-certain-string-macro/m-p/329634#M21910</link>
      <description>&lt;P&gt;I want to write a macro, by using which &lt;U&gt;some columns, if the column name contains a certain string, will then be deleted/dropped&lt;/U&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, &lt;STRONG&gt;one of the dataset will be like&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; LIB.Original_1&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; vector_A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;vector_B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;factor_C&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; b &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; b2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;after macro, it should be something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; LIB.Page_1&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;factor_C&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The macro would be something like:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro dropCol(_name=);&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select name into :droplist separated by ' '&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; from dictionary.columns&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; where libname = 'LIB' and memname = '&lt;SPAN&gt;Original_&lt;/SPAN&gt;'&amp;amp;_name&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; and name like '%vector%';&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data LIB.Page_&amp;amp;_name;&lt;/P&gt;&lt;P&gt;set LIB.Original_&amp;amp;_name;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drop &amp;amp;droplist;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;%mend&amp;nbsp;&lt;SPAN&gt;dropCol;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%dropCol(_name=1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%dropCol(_name=2&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%dropCol(_name=3);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%dropCol(_name=4);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;However it's not working at the moment. The error reported currently comes from '&amp;amp;droplist'.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;It'd be great if someone can fix the codes above or provide other ways of doing the task.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The Error is:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;41           proc sql;  select name into :droplist separated by ''  from dictionary.columns  where libname = 'input' and memname =
41       ! "final_&amp;amp;_name"  and name like '%Est_%'; quit;  data work.temp_&amp;amp;_name; set input.final_&amp;amp;_name;  drop &amp;amp;droplist; run;
                                                                                                               _
                                                                                                               22
2                                                          The SAS System                           08:47 Thursday, February 9, 2017

ERROR 22-322: Syntax error, expecting one of the following: a name, ;, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.  

NOTE: Line generated by the invoked macro "REMOVEE".
41           proc sql;  select name into :droplist separated by ''  from dictionary.columns  where libname = 'input' and memname =
41       ! "final_&amp;amp;_name"  and name like '%Est_%'; quit;  data work.temp_&amp;amp;_name; set input.final_&amp;amp;_name;  drop &amp;amp;droplist; run;
                                                                                                               _
                                                                                                               200
ERROR 200-322: The symbol is not recognized and will be ignored.

MPRINT(REMOVEE):   set input.final_2016;
WARNING: Apparent symbolic reference DROPLIST not resolved.
MPRINT(REMOVEE):   drop &amp;amp;droplist;
MPRINT(REMOVEE):   run;

WARNING: The variable droplist in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.TEMP_2016 may be incomplete.  When this step was stopped there were 0 observations and 42 variables.
WARNING: Data set WORK.TEMP_2016 was not replaced because this step was stopped.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 22:05:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Delete-columns-whose-name-contains-a-certain-string-macro/m-p/329634#M21910</guid>
      <dc:creator>ayin</dc:creator>
      <dc:date>2017-02-08T22:05:47Z</dc:date>
    </item>
    <item>
      <title>Re: Delete columns whose name contains a certain string (macro)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Delete-columns-whose-name-contains-a-certain-string-macro/m-p/329650#M21911</link>
      <description>&lt;P&gt;Since your Proc sql generates error you really should post the log with the error. Use OPTIONS MPRINT to show more details in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;proc sql;
    select name into :droplist separated by ' '
    from dictionary.columns
    where libname = 'LIB' and memname = "Original_&amp;amp;_name" /*&amp;lt;= the ' before name was proximate cause of error*/
                                                          /* place inside double quotes "  " to resolve the macro varialbe*/
    and name like '%vector%';
quit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Feb 2017 23:42:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Delete-columns-whose-name-contains-a-certain-string-macro/m-p/329650#M21911</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-02-02T23:42:29Z</dc:date>
    </item>
    <item>
      <title>Re: Delete columns whose name contains a certain string (macro)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Delete-columns-whose-name-contains-a-certain-string-macro/m-p/329657#M21914</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data want;
  set have(drop=vector:);
run;quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2017 01:42:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Delete-columns-whose-name-contains-a-certain-string-macro/m-p/329657#M21914</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-02-03T01:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: Delete columns whose name contains a certain string (macro)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Delete-columns-whose-name-contains-a-certain-string-macro/m-p/331001#M21960</link>
      <description>&lt;P&gt;Hey it works for columns names like: vector_4, vectorETC.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would you kindly provide a solution for names like ETC_vector_ETC, ETC_vector?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 22:01:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Delete-columns-whose-name-contains-a-certain-string-macro/m-p/331001#M21960</guid>
      <dc:creator>ayin</dc:creator>
      <dc:date>2017-02-08T22:01:48Z</dc:date>
    </item>
    <item>
      <title>Re: Delete columns whose name contains a certain string (macro)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Delete-columns-whose-name-contains-a-certain-string-macro/m-p/594103#M34815</link>
      <description>&lt;P&gt;If the string is a common prefix, approach this like a drop statement, but just use a colon after the prefix&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data table2;&lt;BR /&gt;set table;&lt;BR /&gt;drop column_prefix&lt;STRONG&gt;:&lt;/STRONG&gt; ;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 13:56:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Delete-columns-whose-name-contains-a-certain-string-macro/m-p/594103#M34815</guid>
      <dc:creator>chalita</dc:creator>
      <dc:date>2019-10-04T13:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: Delete columns whose name contains a certain string (macro)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Delete-columns-whose-name-contains-a-certain-string-macro/m-p/594139#M34824</link>
      <description>&lt;P&gt;You should make sure to set DROPLIST empty before the query in case the SELECT statement does not find ANY variables.&lt;/P&gt;
&lt;P&gt;The DROP statement does not like it when no variables are listed. But the DROP= dataset option doesn't mind.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the LIBNAME and MEMNAME variable in the dictionary tables are always in uppercase. So you will never find any records where&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname = 'input' and memname = "final_&amp;amp;_name" &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Plus I doubt that you have any member names with an &amp;amp; in their names. That would be very hard to create and difficult to reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note that the NAME field will store the names in mixed case.&amp;nbsp; So a name like Vector1 or VECTOR2 will never match:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;name like '%vector%'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try something like this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
%let droplist=;
select name
  into :droplist separated by ' '
from dictionary.columns
where libname = 'LIB'
  and memname = "ORIGINAL_%upcase(&amp;amp;_name)"
  and lowcase(name) like '%vector%'
;

quit;

data LIB.Page_&amp;amp;_name;
  set LIB.Original_&amp;amp;_name(drop=&amp;amp;droplist);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 15:42:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Delete-columns-whose-name-contains-a-certain-string-macro/m-p/594139#M34824</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-04T15:42:17Z</dc:date>
    </item>
  </channel>
</rss>

