<?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 certain dataset in library in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-certain-dataset-in-library/m-p/309642#M66708</link>
    <description>&lt;PRE&gt;
You want delete that table if any one of stock price is less than 15 ?


data a;
input id stock_price;
cards;
1 23
2 35
;
run;

data b;
input cusid stock_price;
cards;
2 14
2 34
4 76
;
run;
data c;
input cusid stock_price;
cards;
2 14
2 34
4 76
;
run;
data _null_;
 set sashelp.vmember(where=(libname='WORK' and memtype='DATA')) end=last;
 if _n_=1 then call execute('data temp;length dsn dsname $ 60;set ');
 call execute(cats(libname,'.',memname,'(keep=stock_price)'));
 if last then call execute(' indsname=dsn;
 if stock_price lt 15 then do;dsname=dsn;output;end;run;');
run;
proc sql noprint;
select distinct dsname into : list separated by ','
 from temp;
 
drop table &amp;amp;list;
quit;

&lt;/PRE&gt;</description>
    <pubDate>Mon, 07 Nov 2016 03:26:44 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-11-07T03:26:44Z</dc:date>
    <item>
      <title>Delete certain dataset in library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-certain-dataset-in-library/m-p/309632#M66706</link>
      <description>&lt;P&gt;I use following code to delete datasets if its&amp;nbsp;observation less than 30, but how could I change the criterion? For exampe, deleting dataset if stock_price (one variable in all datasets) less than 15.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql noprint;
select memname into : dellist separated by ' ' from dictionary.tables 
  where libname= work and nobs&amp;lt;30;
quit;

proc datasets nolist;
delete &amp;amp;dellist;
quit;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Nov 2016 00:07:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-certain-dataset-in-library/m-p/309632#M66706</guid>
      <dc:creator>Neal0801</dc:creator>
      <dc:date>2016-11-07T00:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: Delete certain dataset in library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-certain-dataset-in-library/m-p/309638#M66707</link>
      <description>&lt;P&gt;1.&amp;nbsp; The code you show would not work.&amp;nbsp; You need&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where libname='WORK'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. A slightly more compact way would be to use the DROP TABLE statement in PROC SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select distinct memname into :dsnames_with_few_obs separated by ','
    from dictionary.tables where libname='WORK' and nobs&amp;lt;30 ;
  drop table &amp;amp;dsnames_with_few_obs ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. I suppose some tricky progamming in a macro could do your new task in a single PROC SQL, but I recommend the following, which uses PROC SQL&amp;nbsp;only to idenifiy candidates for later assessmment&amp;nbsp;(I use variable AGE).&amp;nbsp; &amp;nbsp;Then a data step uses a hash object recycled over each candidate.&amp;nbsp; Candidates not meeting the cutoff criterion would leave the hash object empty..&amp;nbsp;And the where clause and "OBS=1" clause tells the object to stop building as soon as&amp;nbsp;a single observation has a value below the cut off&amp;nbsp;- no need to go further to find the minimum value of the "successful" candidates:.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;  set sashelp.class;  run;

%let var=AGE;
%let cutoff=12;

proc sql noprint;
  select distinct memname into :dsnames_with_selected_var separated by ' '
    from dictionary.columns where libname='WORK' and upcase(name)="&amp;amp;var";
quit;

data _null_;
  if 0 then set &amp;amp;dsnames_with_selected_var;&lt;BR /&gt;  &lt;STRONG&gt;&lt;U&gt;declare hash h;&lt;/U&gt;&lt;/STRONG&gt;
  do d=1 to &amp;amp;sqlobs;
    length dsn $32;
&lt;STRIKE&gt;    dsn=scan("&amp;amp;dsnames_with_selected_var",d,' ');
&lt;/STRIKE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;&lt;U&gt;h=_new_ hash (dataset:cats(dsn,'(obs=1 keep=&amp;amp;var where=(&amp;amp;var&amp;lt;&amp;amp;cutoff))'));&lt;/U&gt;&lt;/STRONG&gt;&lt;BR /&gt;      h.definekey('age');
      h.definedone();
    if h.num_items  &amp;gt; 0 then call execute(cats("proc delete data=",dsn,';run;'));
    h.clear();
  end;
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;Modified (new statements are underlined&amp;nbsp; Removed statement has strike-through.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Regards,&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2016 14:14:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-certain-dataset-in-library/m-p/309638#M66707</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-11-07T14:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: Delete certain dataset in library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-certain-dataset-in-library/m-p/309642#M66708</link>
      <description>&lt;PRE&gt;
You want delete that table if any one of stock price is less than 15 ?


data a;
input id stock_price;
cards;
1 23
2 35
;
run;

data b;
input cusid stock_price;
cards;
2 14
2 34
4 76
;
run;
data c;
input cusid stock_price;
cards;
2 14
2 34
4 76
;
run;
data _null_;
 set sashelp.vmember(where=(libname='WORK' and memtype='DATA')) end=last;
 if _n_=1 then call execute('data temp;length dsn dsname $ 60;set ');
 call execute(cats(libname,'.',memname,'(keep=stock_price)'));
 if last then call execute(' indsname=dsn;
 if stock_price lt 15 then do;dsname=dsn;output;end;run;');
run;
proc sql noprint;
select distinct dsname into : list separated by ','
 from temp;
 
drop table &amp;amp;list;
quit;

&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Nov 2016 03:26:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-certain-dataset-in-library/m-p/309642#M66708</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-07T03:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: Delete certain dataset in library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-certain-dataset-in-library/m-p/309646#M66709</link>
      <description>&lt;PRE&gt;
It is easy for IML.



data a;
input id stock_price;
cards;
1 23
2 35
;
run;

data b;
input cusid stock_price;
cards;
2 214
2 34
4 76
;
run;
data c;
input cusid stock_price;
cards;
2 14
2 34
4 3
;
run;
proc iml;
x=datasets('work');
dsn='work.'+datasets('work');
do i=1 to nrow(dsn);
 use (dsn[i]);
 read all var{stock_price};
 close;
 if any(stock_price &amp;lt; 15) then call delete('work',x[i]);
end;
quit;


&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Nov 2016 03:41:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-certain-dataset-in-library/m-p/309646#M66709</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-07T03:41:11Z</dc:date>
    </item>
    <item>
      <title>Re: Delete certain dataset in library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-certain-dataset-in-library/m-p/309648#M66710</link>
      <description>&lt;P&gt;Deleting a data set is easy. &amp;nbsp;Defining the problem is harder. &amp;nbsp;What are you really trying to accomplish here?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(a) Delete a SAS data set if the average of STOCK_PRICE is less than 15?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(b) Delete a SAS data set if any value for STOCK_PRICE is less than 15?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(c) Search through an entire folder, and delete all data sets that meet criterion (a) or perhaps criterion (b)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(d) Search through a bunch of folders and delete all data sets that meet criterion (a) or perhaps criterion (b)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the program to search through a folder (or through many folders), is it guaranteed that every data set in the folder(s) contains a numeric variable named STOCK_PRICE?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While the answers to these questions are important, the posts so far have at least answered (in general) one key question that you had. &amp;nbsp;No, you cannot use your existing program. &amp;nbsp;The existing program looks at the header information ... metadata about a SAS data set. &amp;nbsp;Your new requirement needs to look within the data set to examine the data values.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2016 03:59:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-certain-dataset-in-library/m-p/309648#M66710</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-07T03:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: Delete certain dataset in library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-certain-dataset-in-library/m-p/309668#M66717</link>
      <description>&lt;P&gt;Another symptomatic problem which has arisen by having many datasets for the same data. &amp;nbsp;Advice, as always, put your data into one dataset, the problem is vastly simplefied then.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2016 09:21:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-certain-dataset-in-library/m-p/309668#M66717</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-07T09:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: Delete certain dataset in library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-certain-dataset-in-library/m-p/309761#M66746</link>
      <description>Thank you! You gave me two solutions&lt;BR /&gt;</description>
      <pubDate>Mon, 07 Nov 2016 16:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-certain-dataset-in-library/m-p/309761#M66746</guid>
      <dc:creator>Neal0801</dc:creator>
      <dc:date>2016-11-07T16:23:58Z</dc:date>
    </item>
  </channel>
</rss>

