<?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 data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-data-set/m-p/617175#M180802</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
create table tablesa as
select
  memname,
  substr(memname,6) as date_c
from dictionary.tables
where libname = 'WORK' and substr(memname,1,5) = 'TBL_A';
create table tablesb as
select
  memname,
  substr(memname,6) as date_c
from dictionary.tables
where libname = 'WORK' and substr(memname,1,5) = 'TBL_B';
select 'WORK.'!!coalesce(a.memname,b.memname) into :to_delete separated by ' '
from tablesa a full join tablesb b
on a.date_c = b.date_c
where a.memname is missing or b.memname is missing;
quit;

proc delete data=&amp;amp;to_delete.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Jan 2020 12:32:04 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-01-14T12:32:04Z</dc:date>
    <item>
      <title>Delete data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-data-set/m-p/617168#M180800</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have series of data set with two types: Tbl_A and Tbl_B&lt;BR /&gt;Each data set name end with YYMMDD (date).&lt;BR /&gt;For example:&lt;BR /&gt;Tbl_A190827 Tbl_B190827&lt;BR /&gt;Tbl_A190824 Tbl_B190824&lt;BR /&gt;Tbl_A190822 Tbl_B190822&lt;BR /&gt;Tbl_A190823 Tbl_B190823&lt;BR /&gt;Tbl_A190817 No have Tbl_B190817&lt;BR /&gt;I want to create a condition that If for specific date the pair doesn't exist then need to delete the data set.&lt;BR /&gt;For example: Tbl_A190817 exists but Tbl_B190817 so need to delete Tbl_A190817&lt;/P&gt;
&lt;P&gt;For example: Tbl_B190807 doesn't exist but Tbl_A190807 exists&amp;nbsp; so need to delete Tbl_A190807&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 12:09:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-data-set/m-p/617168#M180800</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-01-14T12:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Delete data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-data-set/m-p/617175#M180802</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
create table tablesa as
select
  memname,
  substr(memname,6) as date_c
from dictionary.tables
where libname = 'WORK' and substr(memname,1,5) = 'TBL_A';
create table tablesb as
select
  memname,
  substr(memname,6) as date_c
from dictionary.tables
where libname = 'WORK' and substr(memname,1,5) = 'TBL_B';
select 'WORK.'!!coalesce(a.memname,b.memname) into :to_delete separated by ' '
from tablesa a full join tablesb b
on a.date_c = b.date_c
where a.memname is missing or b.memname is missing;
quit;

proc delete data=&amp;amp;to_delete.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 12:32:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-data-set/m-p/617175#M180802</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-14T12:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: Delete data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-data-set/m-p/617179#M180803</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how about:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data
Tbl_A190827 Tbl_B190827
/*Tbl_A190824*/ Tbl_B190824
Tbl_A190822 /*Tbl_B190822*/
Tbl_A190823 Tbl_B190823
;
x = 1;
run;


%macro test(date=);
%if %eval(%sysfunc(exist(tbl_A&amp;amp;date.,data)) * %sysfunc(exist(tbl_B&amp;amp;date.,data))) = 0
%then
%do;&lt;BR /&gt;options NODSNFERR; /* to avoid warnings in log */
proc delete data = Tbl_A&amp;amp;date. Tbl_B&amp;amp;date.;
run;&lt;BR /&gt;options DSNFERR;
%end;

%mend test;

%test(date=190824)
%test(date=190827)
%test(date=190822)
%test(date=190823)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 12:47:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-data-set/m-p/617179#M180803</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-01-14T12:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: Delete data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-data-set/m-p/617186#M180806</link>
      <description>&lt;P&gt;As an alternative approach I can offer you also my home made `kill()` function which deletes dataset or view by name (not by reference, like `fdelete` does)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* tested on windows and linux */

options cmplib = _NULL_;

proc FCMP
 outlib = work.f.p
;
  function kill(lbds_ $);
    length F $ 8 ds $ 32 lb $ 2048 lbds $ 41;

    F = cats("_",put(datetime(),hex7.));

    lbds = strip(lowcase(lbds_));
    if lbds = '_last_' then lbds = lowcase(symget("syslast"));

    ds = scan(lbds, -1, ".");
    if index(lbds, ".")&amp;gt;0 then lb = pathname(scan(lbds, 1, "."));
                          else lb = pathname(ifc(LIBREF("user"),"work","user"));
    /*put lbds lb ds;*/

    array ext[3] $ 12 (".sas7bdat", ".sas7bndx", ".sas7bvew");

    _RCV_ = 1;
    do i = 1 to dim(ext);
      _RC_ = filename(F, cats(lb, "/", ds, ext[i]), "disk");
      _RCV_ = _RCV_ * fdelete(F);
    end;
    _RC_ = filename(F);

    return(_RCV_);
  endsub;
run;

options cmplib = work.f;


data
Tbl_A190827 Tbl_B190827
/*Tbl_A190824*/ Tbl_B190824
Tbl_A190822 /*Tbl_B190822*/
Tbl_A190823 Tbl_B190823
;
x = 1;
run;


%macro test(date=);
%if %eval(%sysfunc(exist(tbl_A&amp;amp;date.,data)) * %sysfunc(exist(tbl_B&amp;amp;date.,data))) = 0
%then
%do;
%put *%sysfunc(kill(tbl_A&amp;amp;date.))**%sysfunc(kill(tbl_B&amp;amp;date.))*;
%end;

%mend test;

%test(date=190824)
%test(date=190827)
%test(date=190822)
%test(date=190823)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jan 2020 13:13:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-data-set/m-p/617186#M180806</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-01-14T13:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: Delete data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-data-set/m-p/617191#M180809</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Generate example data;
PROC DATASETS lib=work kill nolist;RUN;QUIT;
data Tbl_A190827;set sashelp.class;run; 
/*data Tbl_B190827;set sashelp.class;run; /**/
data Tbl_A190824;set sashelp.class;run; 
data Tbl_B190824;set sashelp.class;run; 
data Tbl_A190822;set sashelp.class;run; 
data Tbl_B190822;set sashelp.class;run; 
data Tbl_A190823;set sashelp.class;run; 
/*data Tbl_B190823;set sashelp.class;run;/**/&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO DeleteNoPair();
   %local memnames;
   %*Determine tables not occurring in pair tbl_Adddddd,tbl_Bdddddd;
   PROC SQL;
      SELECT memname INTO :memnames SEPARATED BY ','
      FROM sashelp.vtable
      WHERE libname eq 'WORK'
      GROUP BY substr(memname,6)
      HAVING count(substr(memname,6)) ne 2
      ;
      %put Deleted tables:&amp;amp;memnames.;
      %*Delete tables found if any;
      %if not %sysevalf(%superq(memnames)=,boolean) %then %do;
         DROP TABLE &amp;amp;memnames.;
      %end;
   QUIT;
%MEND DeleteNoPair;
%DeleteNoPair;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jan 2020 13:33:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-data-set/m-p/617191#M180809</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2020-01-14T13:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: Delete data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-data-set/m-p/617210#M180813</link>
      <description>&lt;P&gt;And another solution, this time using a hash-object:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   set sashelp.vtable(keep=MemName LibName where=(LibName = 'WORK')) end=jobDone;

   if _n_ = 1 then do;
      declare hash h(dataset: 'sashelp.vtable(keep= LibName MemName where=(LibName="WORK"))');
      h.defineKey('MemName');
      h.defineDone();

      call execute('proc datasets library=work nolist;');
   end;

   if prxmatch('/TBL_[AB]\d{6}/', MemName) then do;
      substr(MemName, 5, 1) = ifc(substr(MemName, 5, 1) = 'A', 'B', 'A');
      if h.check() ^= 0 then do; /* check returns non-zero if key is not in the hash-object */
         call execute(catx(' ', 'delete', MemName, ';'));
      end; 
   end;

   if jobDone then do;
      call execute('quit;');
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jan 2020 14:59:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-data-set/m-p/617210#M180813</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-01-14T14:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: Delete data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-data-set/m-p/617334#M180885</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;The task is three-fold:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;find the memnames prefixed with Tbl_A and Tbl_B with the suffixes representing valid dates in the YYMMDD format&lt;/LI&gt;
&lt;LI&gt;out of those, find the memnames whose suffixes have count=1 (i.e. they aren't paired)&lt;/LI&gt;
&lt;LI&gt;drop the corresponding members from the library (e.g. WORK, if that is your library)&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;All three, however, can be done in a single SQL step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Tbl_A190827     Tbl_B190827                                                                                                                                                                                                                                
                     Tbl_B190824                                                                                                                                                                                                                                
     Tbl_A190822                                                                                                                                                                                                                                                
     Tbl_A190823     Tbl_B190823                                                                                                                                                                                                                                
     /* invalid date suffixes */                                                                                                                                                                                                                                
     Tbl_xyz                                                                                                                                                                                                                                                    
     Tbl_191301                                                                                                                                                                                                                                                 
     Tbl_191035                                                                                                                                                                                                                                                 
  ;                                                                                                                                                                                                                                                             
run ;                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                
proc sql noprint ;                                                                                                                                                                                                                                              
  select catx (".", libname, memname) into :drop separated by ","                                                                                                                                                                                               
  from   dictionary.tables                                                                                                                                                                                                                                      
  where  libname = "WORK"                                                                                                                                                                                                                                       
  and    put (memname, $5.) in ("TBL_A", "TBL_B")                                                                                                                                                                                                               
  and    input (substr (memname, 6), yymmdd8.) is not null                                                                                                                                                                                                      
  group  substr (memname, 6)                                                                                                                                                                                                                                    
  having count (*) = 1                                                                                                                                                                                                                                          
  ;                                                                                                                                                                                                                                                             
  drop table &amp;amp;drop ;                                                                                                                                                                                                                                            
quit ;                             
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The log reports:&lt;/P&gt;
&lt;PRE&gt;NOTE: Table WORK.TBL_A190822 has been dropped.
NOTE: Table WORK.TBL_B190824 has been dropped.
&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 22:18:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-data-set/m-p/617334#M180885</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2020-01-14T22:18:21Z</dc:date>
    </item>
  </channel>
</rss>

