<?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=_: variant in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/drop-variant/m-p/71231#M15401</link>
    <description>there is no "common suffix" handler like the colon modifier indicating a common prefix.&lt;BR /&gt;
The usual solution requires filling the list of columns into a macro variable by processing the output of proc contents or dictionary.columns. The former is my preference.&lt;BR /&gt;
proc contents data= your_data_set noprint out= _data_ ; run;&lt;BR /&gt;
proc sql noprint ;&lt;BR /&gt;
select name into :list_of_cols separated by ' ' from &amp;amp;syslast&lt;BR /&gt;
where lowcase(name) like '%_flg' ;&lt;BR /&gt;
quit;&lt;BR /&gt;
then you can use &amp;amp;list_of_cols&lt;BR /&gt;
 &lt;BR /&gt;
Of course this may be no help (if for example: when you do not have a previously defined data set)&lt;BR /&gt;
 &lt;BR /&gt;
good luck&lt;BR /&gt;
peterC</description>
    <pubDate>Mon, 30 May 2011 22:33:28 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2011-05-30T22:33:28Z</dc:date>
    <item>
      <title>drop=_: variant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/drop-variant/m-p/71230#M15400</link>
      <description>(drop= _:) will drop all variables that begin with an underscore (_).  &lt;BR /&gt;
&lt;BR /&gt;
Is there a way to globally drop variables that end with a common set of characters, e.g.&lt;BR /&gt;
_Flg?  There are anywhere from 3 to 7 characters in front of the _Flg.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Bill</description>
      <pubDate>Mon, 30 May 2011 20:37:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/drop-variant/m-p/71230#M15400</guid>
      <dc:creator>Bill</dc:creator>
      <dc:date>2011-05-30T20:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: drop=_: variant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/drop-variant/m-p/71231#M15401</link>
      <description>there is no "common suffix" handler like the colon modifier indicating a common prefix.&lt;BR /&gt;
The usual solution requires filling the list of columns into a macro variable by processing the output of proc contents or dictionary.columns. The former is my preference.&lt;BR /&gt;
proc contents data= your_data_set noprint out= _data_ ; run;&lt;BR /&gt;
proc sql noprint ;&lt;BR /&gt;
select name into :list_of_cols separated by ' ' from &amp;amp;syslast&lt;BR /&gt;
where lowcase(name) like '%_flg' ;&lt;BR /&gt;
quit;&lt;BR /&gt;
then you can use &amp;amp;list_of_cols&lt;BR /&gt;
 &lt;BR /&gt;
Of course this may be no help (if for example: when you do not have a previously defined data set)&lt;BR /&gt;
 &lt;BR /&gt;
good luck&lt;BR /&gt;
peterC</description>
      <pubDate>Mon, 30 May 2011 22:33:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/drop-variant/m-p/71231#M15401</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-05-30T22:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: drop=_: variant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/drop-variant/m-p/71232#M15402</link>
      <description>Here is a working custom macro "function" you can use to generate a list of  variables ending in a suffix text pattern.  It takes two parameters - the dataset name, and the suffix text:&lt;BR /&gt;
&lt;BR /&gt;
%Macro EndsWith(DSN,Suffix);&lt;BR /&gt;
   %local dsid varlist rc whr lib ds;&lt;BR /&gt;
   /* Parameter Validation */&lt;BR /&gt;
   %if &amp;amp;suffix= %then %do;&lt;BR /&gt;
      %PUT ERROR: You must specify a suffix;&lt;BR /&gt;
      %GoTo EndMacro;&lt;BR /&gt;
   %end;&lt;BR /&gt;
   %if &amp;amp;DSN= %then %let DSN=&amp;amp;SYSLAST;&lt;BR /&gt;
   %let ds=%QSCAN(%QUPCASE(%SUPERQ(DSN)),2);&lt;BR /&gt;
   %if &amp;amp;ds= %then %do;&lt;BR /&gt;
      %let lib=WORK;&lt;BR /&gt;
      %let ds=%QUPCASE(%SUPERQ(DSN));&lt;BR /&gt;
   %end;&lt;BR /&gt;
   %else %let lib=%qscan(%QUPCASE(&amp;amp;DSN),1);&lt;BR /&gt;
   /* Get Variable Names */&lt;BR /&gt;
   %let whr=(WHERE=(LIBNAME="&amp;amp;lib" AND MEMNAME="&amp;amp;ds" AND UPCASE(NAME) like %STR(%')%nrstr(%%)%str(%QUPCASE(%SUPERQ(suffix))%')));&lt;BR /&gt;
   %let dsid=%sysfunc(open(sashelp.vcolumn&amp;amp;whr));&lt;BR /&gt;
   %if &amp;amp;dsid=0 %then %do;&lt;BR /&gt;
      %PUT ERROR: &amp;amp;DSN not opened;&lt;BR /&gt;
      %put ERROR- WHERE: &amp;amp;whr;&lt;BR /&gt;
      %PUT ERROR- &amp;amp;sysmsg;&lt;BR /&gt;
      %GoTo EndMacro;&lt;BR /&gt;
   %end;&lt;BR /&gt;
   %let rc=0;&lt;BR /&gt;
   %do %while (&amp;amp;rc=0);&lt;BR /&gt;
      %let rc=%sysfunc(fetch(&amp;amp;dsid));&lt;BR /&gt;
      %if &amp;amp;rc=0 %then %do;&lt;BR /&gt;
         %let varlist=&amp;amp;varlist %sysfunc(getvarc(&amp;amp;dsid,%sysfunc(varnum(&amp;amp;dsid,NAME))));&lt;BR /&gt;
      %end;&lt;BR /&gt;
   %end;&lt;BR /&gt;
   &amp;amp;varlist&lt;BR /&gt;
%Endmacro:&lt;BR /&gt;
   %let rc=%sysfunc(close(&amp;amp;dsid)); &lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Here are some usage examples:&lt;BR /&gt;
&lt;BR /&gt;
/*Write a list of the variables that end in 't' to the log:*/&lt;BR /&gt;
&lt;BR /&gt;
%PUT NOTE: Variables are %EndsWith(sashelp.class,t);&lt;BR /&gt;
&lt;BR /&gt;
/*Drop variables that end in 't' from the input dataset:*/&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
  set sashelp.class(drop=%EndsWith(sashelp.class,t));&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 01 Jun 2011 22:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/drop-variant/m-p/71232#M15402</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2011-06-01T22:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: drop=_: variant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/drop-variant/m-p/71233#M15403</link>
      <description>SASjedi&lt;BR /&gt;
 &lt;BR /&gt;
thank you for posting the demo macro to collect from a filter of sashelp.vcolumn.&lt;BR /&gt;
Have you compared the times? On my -ix SAS system the demo data step takes 11 seconds real and 1.8 cpu seconds.&lt;BR /&gt;
SAShelp.vcolumn is a list of every column in every table in every library that is assigned in the SAS session, so sometimes it is just slow, and sometimes it is very slow. Because you open the view in data step functions there is no optimisation of the WHERE conditions. When you can open in SQL, filters on libname and memname make the performance a whole lot more acceptable.&lt;BR /&gt;
 &lt;BR /&gt;
peterC</description>
      <pubDate>Thu, 02 Jun 2011 15:53:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/drop-variant/m-p/71233#M15403</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-06-02T15:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: drop=_: variant</title>
      <link>https://communities.sas.com/t5/SAS-Programming/drop-variant/m-p/71234#M15404</link>
      <description>Because the macro utility uses only macro code (does not generate DATA step or PROC  code), it can be leveraged to generate the variable list in-line with other SAS code, much like the macro functions that ship with SAS. &lt;BR /&gt;
&lt;BR /&gt;
Querying dictionary.columns in PROC SQL is definitely more efficient in execution, but it is not possible to use the PROC SQL query directly in-line with other SAS code (the query must be "pre-executed") so that approach is somewhat less flexible.  &lt;BR /&gt;
&lt;BR /&gt;
It's good to have options, and in this case having a utility that can be used anywhere may override the performance considerations.  And it was an irresistible opportunity to showcase the ability to access data in a purely macro environment... &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 02 Jun 2011 18:53:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/drop-variant/m-p/71234#M15404</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2011-06-02T18:53:25Z</dc:date>
    </item>
  </channel>
</rss>

