<?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: Wildcard to delete variable with common suffix in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Wildcard-to-delete-variable-with-common-suffix/m-p/875625#M345981</link>
    <description>&lt;P&gt;If the variables are in adjacent positions in your data set you may be able to use the -- list builder. Run Proc Contents using the VARNUM option to display the variables in column order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you may need to show the code of what you attempted. SAS doesn't normally "delete" variables. It can DROP them from reading a data set or on writing to an output data set.&lt;/P&gt;</description>
    <pubDate>Sun, 14 May 2023 03:31:34 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-05-14T03:31:34Z</dc:date>
    <item>
      <title>Wildcard to delete variable with common suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wildcard-to-delete-variable-with-common-suffix/m-p/875624#M345980</link>
      <description>&lt;P&gt;Is there any way to delete multiple variables that ends with a common suffix using a wildcard?&lt;BR /&gt;For example, I have variables: a_suf, b_suf...z_suf. I tried to drop them using drop :_suf; but it didn't work.&lt;/P&gt;</description>
      <pubDate>Sun, 14 May 2023 01:21:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wildcard-to-delete-variable-with-common-suffix/m-p/875624#M345980</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-05-14T01:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: Wildcard to delete variable with common suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wildcard-to-delete-variable-with-common-suffix/m-p/875625#M345981</link>
      <description>&lt;P&gt;If the variables are in adjacent positions in your data set you may be able to use the -- list builder. Run Proc Contents using the VARNUM option to display the variables in column order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you may need to show the code of what you attempted. SAS doesn't normally "delete" variables. It can DROP them from reading a data set or on writing to an output data set.&lt;/P&gt;</description>
      <pubDate>Sun, 14 May 2023 03:31:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wildcard-to-delete-variable-with-common-suffix/m-p/875625#M345981</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-14T03:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: Wildcard to delete variable with common suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wildcard-to-delete-variable-with-common-suffix/m-p/875637#M345982</link>
      <description>&lt;P&gt;SELECT the variable names INTO a macro variable from DICTIONARY.COLUMNS (SEPARATED BY " ")&amp;nbsp; in PROC SQL, and use the macro variable in a DROP statement or DROP= dataset option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select name into :droplist separated by " "
from dictionary.columns
where libname = "WORK" and memname = "HAVE" and scan(upcase(name),-1,'_') = "SUF";
quit;

data want;
set have;
drop &amp;amp;droplist.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 14 May 2023 05:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wildcard-to-delete-variable-with-common-suffix/m-p/875637#M345982</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-14T05:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: Wildcard to delete variable with common suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wildcard-to-delete-variable-with-common-suffix/m-p/875638#M345983</link>
      <description>&lt;P&gt;You could use &lt;A href="https://github.com/SASPAC/baseplus" target="_blank" rel="noopener"&gt;BasePlus&lt;/A&gt; package &lt;A href="https://github.com/SASPAC/baseplus/blob/main/baseplus.md#getvars-macro" target="_blank" rel="noopener"&gt;%getVars()&lt;/A&gt; macro:&lt;/P&gt;
&lt;P&gt;Code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
a=1;
b=1;
z=1;
a_suf=1;
b_suf=1;
z_suf=1;
;
run;

%put %getVars(test, pattern = _suf$); /* regular expression for sufix "_suf" */

data test2;
  set test( drop=%getVars(test, pattern = _suf$) );
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1    data test;
2    a=1;
3    b=1;
4    z=1;
5    a_suf=1;
6    b_suf=1;
7    z_suf=1;
8    ;
9    run;

NOTE: The data set WORK.TEST has 1 observations and &lt;STRONG&gt;6 variables&lt;/STRONG&gt;.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      user cpu time       0.00 seconds
      system cpu time     0.00 seconds
      memory              393.90k
      OS Memory           23804.00k

10
11   %put %getVars(test, pattern = _suf$);
a_suf b_suf z_suf
12
13   data test2;
14     set test( drop=%getVars(test, pattern = _suf$) );
15   run;

NOTE: There were 1 observations read from the data set WORK.TEST.
NOTE: The data set WORK.TEST2 has 1 observations and&lt;STRONG&gt; 3 variables&lt;/STRONG&gt;.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      user cpu time       0.00 seconds
      system cpu time     0.01 seconds
      memory              568.00k
      OS Memory           23804.00k
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Enable &lt;A href="https://github.com/yabwon/SAS_PACKAGES" target="_blank" rel="noopener"&gt;SAS Packages Framework&lt;/A&gt; and load BasePlus package:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename packages "/your/path/to/packages";
%include packages(SPFinit.sas);

%loadPackage(BasePlus)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(details under &lt;A href="https://github.com/yabwon/SAS_PACKAGES#the-user" target="_blank" rel="noopener"&gt;The User&lt;/A&gt; section of readme.md)&lt;/P&gt;</description>
      <pubDate>Sun, 14 May 2023 07:31:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wildcard-to-delete-variable-with-common-suffix/m-p/875638#M345983</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-05-14T07:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: Wildcard to delete variable with common suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wildcard-to-delete-variable-with-common-suffix/m-p/875639#M345984</link>
      <description>&lt;P&gt;Thanks all of you for suggesting the codes and Macro. It seems that SAS doesn't allow the use of wildcard for suffix which is a shame. Other packages, such as Stata allows wildcard in both side of a keyword. For example, drop *_suf would delete all the variables that ends with _suf and drop pref_* will delete all the variables that starts with pref_. Is it worth requesting SAS to add this simple feature in its future release?&lt;/P&gt;</description>
      <pubDate>Sun, 14 May 2023 07:50:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wildcard-to-delete-variable-with-common-suffix/m-p/875639#M345984</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-05-14T07:50:33Z</dc:date>
    </item>
    <item>
      <title>Re: Wildcard to delete variable with common suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wildcard-to-delete-variable-with-common-suffix/m-p/875640#M345985</link>
      <description>&lt;P&gt;Prefix dropping works pretty well:&lt;/P&gt;
&lt;P&gt;Code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
a=1;
b=1;
z=1;
a_suf=1;
b_suf=1;
z_suf=1;
;
run;

data test2;
  set test( drop=a: b:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1    data test;
2    a=1;
3    b=1;
4    z=1;
5    a_suf=1;
6    b_suf=1;
7    z_suf=1;
8    ;
9    run;

NOTE: The data set WORK.TEST has 1 observations and &lt;STRONG&gt;6 variables&lt;/STRONG&gt;.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      user cpu time       0.00 seconds
      system cpu time     0.01 seconds
      memory              393.93k
      OS Memory           23804.00k

10
11   data test2;
12     set test( drop=a: b:);
13   run;

NOTE: There were 1 observations read from the data set WORK.TEST.
NOTE: The data set WORK.TEST2 has 1 observations and &lt;STRONG&gt;2 variables&lt;/STRONG&gt;.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      user cpu time       0.00 seconds
      system cpu time     0.00 seconds
      memory              555.34k
      OS Memory           23804.00k
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 May 2023 07:59:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wildcard-to-delete-variable-with-common-suffix/m-p/875640#M345985</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-05-14T07:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: Wildcard to delete variable with common suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wildcard-to-delete-variable-with-common-suffix/m-p/875641#M345986</link>
      <description>&lt;P&gt;One more approach with Proc Transpose trick:&lt;/P&gt;
&lt;P&gt;Code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
a=1;
b=1;
z=1;
a_suf=1;
b_suf=1;
z_suf=1;
;
run;


proc transpose data=test(obs=0) out=temp(keep=_name_);
  var _all_;
run;

filename f TEMP;
data _null_;
  file f;
  put "data test2; set test( drop=";

  do until (EOF);
    set temp end=EOF;
    where _NAME_ like '%\_suf' ESCAPE "\";
    put _NAME_;
  end;

  put "); run;";
stop;
run;
%include f / source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1    data test;
2    a=1;
3    b=1;
4    z=1;
5    a_suf=1;
6    b_suf=1;
7    z_suf=1;
8    ;
9    run;

NOTE: The data set WORK.TEST has 1 observations and &lt;STRONG&gt;6 variables&lt;/STRONG&gt;.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      user cpu time       0.01 seconds
      system cpu time     0.00 seconds
      memory              391.65k
      OS Memory           23804.00k

10
11
12   proc transpose data=test(obs=0) out=temp(keep=_name_);
13     var _all_;
14   run;

NOTE: There were 0 observations read from the data set WORK.TEST.
NOTE: The data set WORK.TEMP has 6 observations and 1 variables.
NOTE: PROCEDURE TRANSPOSE used (Total process time):
      real time           0.00 seconds
      user cpu time       0.00 seconds
      system cpu time     0.01 seconds
      memory              2448.75k
      OS Memory           25856.00k

15
16   filename f TEMP;
17   data _null_;
18     file f;
19     put "data test2; set test( drop=";
20
21     do until (EOF);
22       set temp end=EOF;
23       where _NAME_ like '%\_suf' ESCAPE "\";
24       put _NAME_;
25     end;
26
27     put "); run;";
28   stop;
29   run;

NOTE: The file F is:
      Filename=*************************\#LN00610,
      RECFM=V,LRECL=32767,File Size (bytes)=0,

NOTE: 5 records were written to the file F.
      The minimum record length was 5.
      The maximum record length was 27.
NOTE: There were 3 observations read from the data set WORK.TEMP.
      WHERE _NAME_ like '%\_suf' escape '\';
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      user cpu time       0.01 seconds
      system cpu time     0.00 seconds
      memory              494.25k
      OS Memory           23804.00k

30   %include f / source2;
NOTE: %INCLUDE (level 1) file F is file 
*************************\#LN00610.
31  +data test2; set test( drop=
32  +a_suf
33  +b_suf
34  +z_suf
35  +); run;

NOTE: There were 1 observations read from the data set WORK.TEST.
NOTE: The data set WORK.TEST2 has 1 observations and &lt;STRONG&gt;3 variables&lt;/STRONG&gt;.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      user cpu time       0.00 seconds
      system cpu time     0.00 seconds
      memory              555.21k
      OS Memory           23804.00k

NOTE: %INCLUDE (level 1) ending
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 May 2023 08:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wildcard-to-delete-variable-with-common-suffix/m-p/875641#M345986</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-05-14T08:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: Wildcard to delete variable with common suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wildcard-to-delete-variable-with-common-suffix/m-p/875642#M345987</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/437116"&gt;@BayzidurRahman&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is it worth requesting SAS to add this simple feature in its future release?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No. The colon on its own or as a prefix is already used in the SAS language (e.g. colon modifier in INPUT).&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Experienced SAS coders always use prefixes, as they are aware of the limitation.&lt;/P&gt;</description>
      <pubDate>Sun, 14 May 2023 08:12:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wildcard-to-delete-variable-with-common-suffix/m-p/875642#M345987</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-14T08:12:54Z</dc:date>
    </item>
  </channel>
</rss>

