<?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: Deleting dataset with no observations in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/869687#M343529</link>
    <description>&lt;P&gt;same result with:&lt;/P&gt;&lt;P&gt;%macro apaga;&lt;BR /&gt;%do i=1 %to 9;&lt;BR /&gt;%let EMPTY=1;&lt;BR /&gt;data _null_;&lt;BR /&gt;set x&amp;amp;i;&lt;BR /&gt;call symput('EMPTY','0'); /* this will only occur if &amp;amp;DATA is not empty */&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;/*&lt;BR /&gt;Now, you just need to check the macro var for its value at the end, to perform (or not) a proc dataset delete,*/&lt;/P&gt;&lt;P&gt;%if &amp;amp;EMPTY %then %do;&lt;BR /&gt;proc datasets lib=work nolist;&lt;BR /&gt;delete work.x&amp;amp;i;&lt;BR /&gt;%end;/*%end;***also tried put it all inside teh first 2 loops and the result was the same***/&lt;BR /&gt;quit;&lt;BR /&gt;%mend;&lt;BR /&gt;%apaga; run;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Apr 2023 00:03:07 GMT</pubDate>
    <dc:creator>Angela53</dc:creator>
    <dc:date>2023-04-14T00:03:07Z</dc:date>
    <item>
      <title>Deleting dataset with no observations in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/46170#M9547</link>
      <description>I am wondering how to automatically delete an entire dataset if there are no observations.  The macro I created scrolls through an entire library and manipulates all the datasets within the library.  However there are a few that have no observations and the macro still creates them as an ouput dataset.  I don't want to use proc datasets and the specific dataset name to get rid of them because they may have data in them in the future.  These datasets are causing errors later on in my code.</description>
      <pubDate>Wed, 17 Jun 2009 19:35:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/46170#M9547</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-17T19:35:27Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting dataset with no observations in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/46171#M9548</link>
      <description>Refer the below link. It might be helpful for your situation. &lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi26/p095-26.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi26/p095-26.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
~ Sukanya E</description>
      <pubDate>Wed, 17 Jun 2009 20:15:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/46171#M9548</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-17T20:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting dataset with no observations in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/46172#M9549</link>
      <description>The referenced paper makes mention of observation level deletion, not file deletion.  Explore using DICTONARY.MEMBERS (SAS-maintained view) with PROC SQL to detect an empty SAS member and generate PROC DELETE code. &lt;BR /&gt;
&lt;BR /&gt;
Have a look at the SAS support  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  website for SAS-hosted documentation and technical/conference papers, using the SEARCH facility or Google advanced search with the parameter site:sas.com  (limits the search).&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 17 Jun 2009 21:34:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/46172#M9549</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-06-17T21:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting dataset with no observations in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/46173#M9550</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Please try this&lt;BR /&gt;
&lt;BR /&gt;
Proc sql;&lt;BR /&gt;
select memname into:tables separated by " "&lt;BR /&gt;
from dictionary.tables&lt;BR /&gt;
where LIBNAME="&lt;B&gt;&lt;I&gt;library-name in capitals&lt;/I&gt;&lt;/B&gt;"  and NOBS NE 0;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
%put &amp;amp;tables.;&lt;BR /&gt;
&lt;BR /&gt;
This code will create a macro with all the dataset names  having atleast one observation.&lt;BR /&gt;
&lt;BR /&gt;
We can use this macro for furthur use</description>
      <pubDate>Thu, 18 Jun 2009 11:25:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/46173#M9550</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-18T11:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting dataset with no observations in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/46174#M9551</link>
      <description>Thanks to all who responded.  Got it to work.  Plus thanks for the pointers to other documentation for future reference</description>
      <pubDate>Thu, 18 Jun 2009 14:01:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/46174#M9551</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-18T14:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting dataset with no observations in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/46175#M9552</link>
      <description>Another approach would be to code a macro that will delete the dataset (name passed as argument) if it is indeed empty.&lt;BR /&gt;
&lt;BR /&gt;
You see, no datastep code will execute if the dataset is empty.&lt;BR /&gt;
&lt;BR /&gt;
So, if you try to assign a value to a macro var from within the datastep, this assignment will only occur if the dataset has at least one row.&lt;BR /&gt;
&lt;BR /&gt;
Assume that the dataset is empty, let say:&lt;BR /&gt;
&lt;BR /&gt;
%let EMPTY=1;&lt;BR /&gt;
&lt;BR /&gt;
Then try to reset the macro var within the datastep;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
set &amp;amp;DATA;&lt;BR /&gt;
call symput('EMPTY','0'); /* this will only occur if &amp;amp;DATA is not empty */&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Now, you just need to check the macro var for its value at the end, to perform (or not) a proc dataset delete,&lt;BR /&gt;
&lt;BR /&gt;
%if &amp;amp;EMPTY %then %do;&lt;BR /&gt;
proc dataset lib=&amp;amp;LIB nolist;&lt;BR /&gt;
delete &amp;amp;DATA; /* delete dataset */&lt;BR /&gt;
quit;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
Next, you just need to invoke the macro at every point where it is needed.&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Thu, 18 Jun 2009 14:13:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/46175#M9552</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-06-18T14:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting dataset with no observations in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/869678#M343523</link>
      <description>&lt;P&gt;Can you please tell me where I missed something? I need to run a bunch of macros that keep creating 9 temporary datasets, then delete the empty one before going to the next step of the calculations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried your macro after I created the temp files. It checks how many observations but does not delete the empty ones.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;%macro apaga;&lt;BR /&gt;%let EMPTY=1;&lt;BR /&gt;%do i=1 %to 9;&lt;BR /&gt;data _null_;&lt;BR /&gt;set x&amp;amp;i;&lt;BR /&gt;call symput('EMPTY','0'); /* this will only occur if &amp;amp;DATA is not empty */&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;/*&lt;BR /&gt;Now, you just need to check the macro var for its value at the end, to perform (or not) a proc dataset delete,&lt;BR /&gt;*/&lt;BR /&gt;%if &amp;amp;EMPTY %then %do;&lt;BR /&gt;proc dataset lib=work nolist;&lt;BR /&gt;delete work.x&amp;amp;i; /* delete dataset */&lt;BR /&gt;quit;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%apaga; run;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 23:06:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/869678#M343523</guid>
      <dc:creator>Angela53</dc:creator>
      <dc:date>2023-04-13T23:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting dataset with no observations in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/869679#M343524</link>
      <description>&lt;P&gt;So as soon as you find one non-empty dataset you will never find any more empty datasets because EMPTY will never be set back to true.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Move the %LET statement inside the %DO loop.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 23:20:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/869679#M343524</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-13T23:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting dataset with no observations in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/869680#M343525</link>
      <description>&lt;P&gt;How about trying this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;EMPTY = 1 %then %do;
proc dataset lib=work nolist;
delete work.x&amp;amp;i; /* delete dataset */
quit;
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Apr 2023 23:25:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/869680#M343525</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-04-13T23:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting dataset with no observations in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/869685#M343527</link>
      <description>same results.. counts nobs but does not delete empties...&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Apr 2023 23:59:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/869685#M343527</guid>
      <dc:creator>Angela53</dc:creator>
      <dc:date>2023-04-13T23:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting dataset with no observations in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/869686#M343528</link>
      <description>&lt;P&gt;same result. If the variable x is binary, if x means the same as if x=1.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 23:59:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/869686#M343528</guid>
      <dc:creator>Angela53</dc:creator>
      <dc:date>2023-04-13T23:59:32Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting dataset with no observations in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/869687#M343529</link>
      <description>&lt;P&gt;same result with:&lt;/P&gt;&lt;P&gt;%macro apaga;&lt;BR /&gt;%do i=1 %to 9;&lt;BR /&gt;%let EMPTY=1;&lt;BR /&gt;data _null_;&lt;BR /&gt;set x&amp;amp;i;&lt;BR /&gt;call symput('EMPTY','0'); /* this will only occur if &amp;amp;DATA is not empty */&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;/*&lt;BR /&gt;Now, you just need to check the macro var for its value at the end, to perform (or not) a proc dataset delete,*/&lt;/P&gt;&lt;P&gt;%if &amp;amp;EMPTY %then %do;&lt;BR /&gt;proc datasets lib=work nolist;&lt;BR /&gt;delete work.x&amp;amp;i;&lt;BR /&gt;%end;/*%end;***also tried put it all inside teh first 2 loops and the result was the same***/&lt;BR /&gt;quit;&lt;BR /&gt;%mend;&lt;BR /&gt;%apaga; run;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 00:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/869687#M343529</guid>
      <dc:creator>Angela53</dc:creator>
      <dc:date>2023-04-14T00:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting dataset with no observations in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/869689#M343531</link>
      <description>&lt;P&gt;This works for me:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
  set sashelp.class (obs=0);
run;

%macro delete_table;

%let EMPTY=1;

data _null_;
set class;
call symput('EMPTY','0'); 
run;

%put empty = &amp;amp;empty;

%if &amp;amp;EMPTY %then %do;
proc datasets lib=work nolist;
delete class;
run;
quit;
%end;

%mend delete_table;
%delete_table;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 00:40:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/869689#M343531</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-04-14T00:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting dataset with no observations in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/869695#M343532</link>
      <description>&lt;P&gt;Here's a variation that simplifies the logic, eliminating the complications.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro apaga;

   %do i=1 %to 9;
      data _null_;
         if done then call execute("proc delete data=x&amp;amp;i; run;");
         stop;
         set x&amp;amp;i end=done;
      run;
   %end;

%mend;

%apaga&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;By switching to PROC DELETE, the code also can be easier to use if your source data sets are in more than one library.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 02:11:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/869695#M343532</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-04-14T02:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting dataset with no observations in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/869701#M343533</link>
      <description>&lt;P&gt;You need to perform the delete in the loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro apaga;
%do i =1 %to 9;
  proc sql noprint;
  select nobs into :nobs
  from dictionary.tables
  where libname = "WORK" and memname = "X&amp;amp;i.";
  quit;
  %if &amp;amp;nobs. = 0
  %then %do;
    proc delete data=work.x&amp;amp;i.;
    run;
  %end;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Apr 2023 04:51:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/869701#M343533</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-04-14T04:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting dataset with no observations in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/870199#M343721</link>
      <description>&lt;P&gt;Thanks, Kurt. Your correction works perfectly!&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 16:34:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/870199#M343721</guid>
      <dc:creator>Angela53</dc:creator>
      <dc:date>2023-04-17T16:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting dataset with no observations in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/870200#M343722</link>
      <description>Thanks, it works perfectly!</description>
      <pubDate>Mon, 17 Apr 2023 16:34:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/870200#M343722</guid>
      <dc:creator>Angela53</dc:creator>
      <dc:date>2023-04-17T16:34:59Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting dataset with no observations in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/870201#M343723</link>
      <description>&lt;P&gt;one more:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
set sashelp.class (obs=0);
run;


%macro delData(ds);
data _null_;
  if nobs=0 then call execute("proc delete data=&amp;amp;ds.; run;");
  stop;
  set &amp;amp;ds. nobs=nobs;
run;
%mend delData;

%delData(test)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 17:11:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-dataset-with-no-observations-in-macro/m-p/870201#M343723</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-04-17T17:11:24Z</dc:date>
    </item>
  </channel>
</rss>

