<?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 work table conditionally in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/533006#M146094</link>
    <description>&lt;P&gt;Your macro is opening the dataset to check the variable names and then running a data step to overwrite that dataset while it is still open.&lt;/P&gt;
&lt;P&gt;You should close it BEFORE trying to change the dataset.&lt;/P&gt;
&lt;P&gt;If you did want to make a variable if it doesn't already exist then you could do something like this instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro AddVar(ds, var);
%local rc dsid result;
%let dsid = %sysfunc(open(&amp;amp;ds));
%if %sysfunc(varnum(&amp;amp;dsid, &amp;amp;var)) &amp;gt; 0 %then %do;
  %let result = 1;
  %put NOTE: Var &amp;amp;var exists in &amp;amp;ds;
%end;
%else %do;
  %let result = 0;
  %put NOTE: Var &amp;amp;var not exists in &amp;amp;ds;
%end;
%let rc = %sysfunc(close(&amp;amp;dsid));
%if (&amp;amp;result=0) %then %do;

data &amp;amp;ds;
  set &amp;amp;ds;
  &amp;amp;var=0;
run;
%end;
%mend AddVar;

%AddVar(old, score3);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 05 Feb 2019 16:46:42 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-02-05T16:46:42Z</dc:date>
    <item>
      <title>Drop work table conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532713#M145987</link>
      <description>&lt;P&gt;Is there a way to drop a table and conditionally if it exists?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 20:17:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532713#M145987</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2019-02-04T20:17:00Z</dc:date>
    </item>
    <item>
      <title>Drop Work Table Conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532714#M145992</link>
      <description>&lt;P&gt;Is there a way to drop a table and conditionally if it exists?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 20:17:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532714#M145992</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2019-02-04T20:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: Drop Work Table Conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532738#M145996</link>
      <description>&lt;P&gt;This is one way:&lt;/P&gt;
&lt;PRE&gt;data work.class;
   set sashelp.class;
run;

data _null_;
 if exist ("WORK.CLASS") then call execute("proc datasets library=work; delete CLASS;run;quit;") ;
run;&lt;/PRE&gt;
&lt;P&gt;however if your "table" is in a DBMS you likely need to use other tools;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 20:50:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532738#M145996</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-02-04T20:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: Drop Work Table Conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532752#M145998</link>
      <description>&lt;P&gt;I did a proc sql drop for about 50 work tables and it seems to work ok.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 21:20:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532752#M145998</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2019-02-04T21:20:41Z</dc:date>
    </item>
    <item>
      <title>Re: Drop work table conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532776#M146009</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5059"&gt;@DavidPhillips2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is there a way to drop a table and conditionally if it exists?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If this is just about avoiding an error condition when trying to delete a table which doesn't exist (as it would happen with a SQL DROP) then I normally use PROC DATASETS with the NOWARN option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.class;
  set sashelp.class;
run;

proc datasets lib=work nolist nowarn;
  delete class otherTable;
  run;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Feb 2019 22:00:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532776#M146009</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-02-04T22:00:32Z</dc:date>
    </item>
    <item>
      <title>Re: Drop work table conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532790#M146018</link>
      <description>&lt;P&gt;Very similar question:&amp;nbsp; If a table does not exist and I'm trying to rename a column.&amp;nbsp; Is there a way to handle this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a; set b (rename=(&amp;amp;renamePeriods)) c;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But table b does not have columns because of an earlier step.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 22:27:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532790#M146018</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2019-02-04T22:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: Drop work table conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532806#M146031</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5059"&gt;@DavidPhillips2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Very similar question:&amp;nbsp; If a table does not exist and I'm trying to rename a column.&amp;nbsp; Is there a way to handle this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a; set b (rename=(&amp;amp;renamePeriods)) c;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But table b does not have columns because of an earlier step.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Proc datasets lets you modify data in place. So the example I provided with small modifications would allow you to change a variable name, label or format. Instead of Delete you would be looking at Modify with Rename in Datasets syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would not work as a data set option in the code you show but could be run prior to setting the datasets together.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 23:29:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532806#M146031</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-02-04T23:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: Drop work table conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532819#M146032</link>
      <description>&lt;P&gt;Dunno if this will help.&amp;nbsp; But it's not conditional, it just attempts to delete, and doesn't issue an error or warning if the dataset does not exist (which of course is the equivalent outcome of deletion).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/kill.sas" target="_self"&gt;https://github.com/scottbass/SAS/blob/master/Macro/kill.sas&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2019 00:56:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532819#M146032</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-02-05T00:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: Drop work table conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532911#M146071</link>
      <description>&lt;P&gt;How do I check if a table does exist and has no columns?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The logic would be similar to something like this:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data old;&lt;BR /&gt;input ID SCORE1 SCORE2;&lt;BR /&gt;cards;&lt;BR /&gt;24 100 97&lt;BR /&gt;28 98 87&lt;BR /&gt;60 100 97&lt;BR /&gt;65 100 98&lt;BR /&gt;70 99 97&lt;BR /&gt;40 97 99&lt;BR /&gt;190 100 99&lt;BR /&gt;196 100 100&lt;BR /&gt;210 98 85&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%macro VarExist(ds, var);&lt;BR /&gt;%local rc dsid result;&lt;BR /&gt;%let dsid = %sysfunc(open(&amp;amp;ds));&lt;/P&gt;
&lt;P&gt;%if %sysfunc(varnum(&amp;amp;dsid, &amp;amp;var)) &amp;gt; 0 %then %do;&lt;BR /&gt;%let result = 1;&lt;BR /&gt;%put NOTE: Var &amp;amp;var exists in &amp;amp;ds;&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;%let result = 0;&lt;BR /&gt;%put NOTE: Var &amp;amp;var not exists in &amp;amp;ds;&lt;/P&gt;
&lt;P&gt;data old;&lt;/P&gt;
&lt;P&gt;set old;&lt;/P&gt;
&lt;P&gt;score3=0;&lt;/P&gt;
&lt;P&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;%let rc = %sysfunc(close(&amp;amp;dsid));&lt;/P&gt;
&lt;P&gt;%mend VarExist;&lt;/P&gt;
&lt;P&gt;%VarExist(old, score3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/350433#M81457" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/350433#M81457&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: You cannot open WORK.OLD.DATA for output access with member-level control because WORK.OLD.DATA is in use by you in resource &lt;BR /&gt;environment DATASTEP (2).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;because the table already exists...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2019 13:11:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532911#M146071</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2019-02-05T13:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: Drop work table conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532924#M146073</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5059"&gt;@DavidPhillips2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Very similar question:&amp;nbsp; If a table does not exist and I'm trying to rename a column.&amp;nbsp; Is there a way to handle this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a; set b (rename=(&amp;amp;renamePeriods)) c;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But table b does not have columns because of an earlier step.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There are SAS options to control messages for issue with DROP KEEP RENAME dataset options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; DKRICOND=ERROR    Specifies the error level to report when a variable is missing from an input
                   data set during the processing of a DROP=, KEEP=, or RENAME= data set option.
 DKROCOND=WARN     Specifies the error level to report when a variable is missing from an output
                   data set during the processing of a DROP=, KEEP=, or RENAME= data set option.&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Feb 2019 14:06:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/532924#M146073</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-02-05T14:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: Drop work table conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/533000#M146093</link>
      <description>&lt;P&gt;The error means what it says, somewhere you are using the data set referenced. I don't see any CLOSE before the data step that attempts to use the same data set, so that's the likely culprit in your macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One&amp;nbsp;example of finding out if a data set that exists has any variables:&lt;/P&gt;
&lt;PRE&gt;data work.junk;
run;

proc sql;
   select nvar into : nvars
   from dictionary.tables
   where libname='WORK' and 
         memname='JUNK'
   ;
run;

%put Number of Vars in Work.Junk is &amp;amp;nvars.;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Feb 2019 16:37:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/533000#M146093</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-02-05T16:37:56Z</dc:date>
    </item>
    <item>
      <title>Re: Drop work table conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/533006#M146094</link>
      <description>&lt;P&gt;Your macro is opening the dataset to check the variable names and then running a data step to overwrite that dataset while it is still open.&lt;/P&gt;
&lt;P&gt;You should close it BEFORE trying to change the dataset.&lt;/P&gt;
&lt;P&gt;If you did want to make a variable if it doesn't already exist then you could do something like this instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro AddVar(ds, var);
%local rc dsid result;
%let dsid = %sysfunc(open(&amp;amp;ds));
%if %sysfunc(varnum(&amp;amp;dsid, &amp;amp;var)) &amp;gt; 0 %then %do;
  %let result = 1;
  %put NOTE: Var &amp;amp;var exists in &amp;amp;ds;
%end;
%else %do;
  %let result = 0;
  %put NOTE: Var &amp;amp;var not exists in &amp;amp;ds;
%end;
%let rc = %sysfunc(close(&amp;amp;dsid));
%if (&amp;amp;result=0) %then %do;

data &amp;amp;ds;
  set &amp;amp;ds;
  &amp;amp;var=0;
run;
%end;
%mend AddVar;

%AddVar(old, score3);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Feb 2019 16:46:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/533006#M146094</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-02-05T16:46:42Z</dc:date>
    </item>
    <item>
      <title>Re: Drop work table conditionally</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/533117#M146126</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5059"&gt;@DavidPhillips2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;How do I check if a table does exist and &lt;STRONG&gt;has no columns&lt;/STRONG&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;SB:&amp;nbsp; How do you encounter this situation?&amp;nbsp; I mean, it's possible, but in all my years of SAS programming I've very rarely if ever encountered it.&amp;nbsp; And I've never had to trap for it.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The logic would be similar to something like this:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data old;&lt;BR /&gt;input ID SCORE1 SCORE2;&lt;BR /&gt;cards;&lt;BR /&gt;24 100 97&lt;BR /&gt;28 98 87&lt;BR /&gt;60 100 97&lt;BR /&gt;65 100 98&lt;BR /&gt;70 99 97&lt;BR /&gt;40 97 99&lt;BR /&gt;190 100 99&lt;BR /&gt;196 100 100&lt;BR /&gt;210 98 85&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%macro VarExist(ds, var);&lt;BR /&gt;%local rc dsid result;&lt;BR /&gt;%let dsid = %sysfunc(open(&amp;amp;ds));&lt;/P&gt;&lt;P&gt;%if %sysfunc(varnum(&amp;amp;dsid, &amp;amp;var)) &amp;gt; 0 %then %do;&lt;BR /&gt;%let result = 1;&lt;BR /&gt;%put NOTE: Var &amp;amp;var exists in &amp;amp;ds;&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;%let result = 0;&lt;BR /&gt;%put NOTE: Var &amp;amp;var not exists in &amp;amp;ds;&lt;/P&gt;&lt;P&gt;data old;&lt;/P&gt;&lt;P&gt;set old;&lt;/P&gt;&lt;P&gt;score3=0;&lt;/P&gt;&lt;P&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%let rc = %sysfunc(close(&amp;amp;dsid));&lt;/P&gt;&lt;P&gt;%mend VarExist;&lt;/P&gt;&lt;P&gt;%VarExist(old, score3);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;SB:&amp;nbsp; Your macro is testing for the existence of a particularly named variable.&amp;nbsp; Not "...check if a table does exist and has no columns".&amp;nbsp; So which is it?&amp;nbsp; What is your actual problem?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/350433#M81457" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/SAS-query/m-p/350433#M81457&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: You cannot open WORK.OLD.DATA for output access with member-level control because WORK.OLD.DATA is in use by you in resource&lt;BR /&gt;environment DATASTEP (2).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;because the table already exists...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Check:&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/varexist.sas" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/varexist.sas&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/varlist.sas" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/varlist.sas&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/varlist2.sas" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/varlist2.sas&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example calls:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;

data empty;
   stop;
run;

%put %varexist(sashelp.doesnotexist,foo);
%put %varexist(sashelp.class,sex);
%put %varexist(sashelp.class,foo);
%put %varexist(empty,foo);
%put %varexist(empty);  * error, var is required ;

%put %varlist(sashelp.doesnotexist);  * error, dataset must exist ;
%put %varlist(sashelp.class);
%put %varlist(empty);

%let empty=%eval(%varlist(sashelp.class) eq %str());  * test for empty string (or modify the macro) ;
%put &amp;amp;=empty;
%let empty=%eval(%varlist(empty) eq %str());  * test for empty string ;
%put &amp;amp;=empty;

%let varlist=;
%varlist2(sashelp.class (keep=name age sex));
%put &amp;amp;=varlist;

%let varlist=;
%varlist2(sashelp.class (keep=_numeric_));
%put &amp;amp;=varlist;

%let varlist=;
%varlist2(empty);
%put &amp;amp;=varlist;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Read the macro header for other use cases...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Feb 2019 02:02:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-work-table-conditionally/m-p/533117#M146126</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-02-06T02:02:00Z</dc:date>
    </item>
  </channel>
</rss>

