<?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 _delete_empty_tables in SAS Users Group in Israel</title>
    <link>https://communities.sas.com/t5/SAS-Users-Group-in-Israel/delete-empty-tables/m-p/650146#M29</link>
    <description>&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;לפעמים מצטברות בספרייה מסוימת לא מעט טבלאות אשר אינן מכילות תצפיות..&lt;/P&gt;&lt;P&gt;המאקרו הבא משמש למחיקה גורפת של כל הטבלאות הריקות תחת ספרייה מסוימת.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro _delete_empty_tables(my_lib);

	%macro dummy;%mend dummy;

	/* Obtain option and temporarily turn off */
	%local user_source user_notes;
	%let user_source=%sysfunc(getoption(source));
	%let user_notes =%sysfunc(getoption(notes));

	option nosource nonotes;

	/*----------------------------------------------------------------------------------
		Declare local variables 
	  ----------------------------------------------------------------------------------*/
	%local _n_ds _i cur_ds cur_dm n_obs;

	/*----------------------------------------------------------------------------------
		Prepare list of all datasets in library 
	  ----------------------------------------------------------------------------------*/
	proc contents data=&amp;amp;my_lib.._all_ noprint nodetails directory out= work._ds_list (where=(MEMTYPE='DATA' and memname ne '_DS_LIST'));run;
	proc sort data= work._ds_list (keep=libname memname) nodupkeys;by libname memname;run;

	/*----------------------------------------------------------------------------------
		Determine number of datasets 
	  ----------------------------------------------------------------------------------*/
	proc sql noprint;
		select count(*) into: _n_ds
		from _ds_list;
	quit;
	%put *** Libref: "&amp;amp;my_lib" Contains: &amp;amp;_n_ds datasets;
	%put ***;

	/*----------------------------------------------------------------------------------
		Itterate on all tables 
	  ----------------------------------------------------------------------------------*/
	%do _i=1 %to &amp;amp;_n_ds;

		/*----------------------------------------------------------------------------------
			Point single table 
	  	  ----------------------------------------------------------------------------------*/
		data _null_;
			rec_num=&amp;amp;_i;
			set _ds_list point=rec_num;
			call symput("cur_ds",cats(libname,'.',memname));
			call symput("cur_dm",strip(memname));
			stop;
		run;

		/*----------------------------------------------------------------------------------
			Count observations in table 
	  	  ----------------------------------------------------------------------------------*/
		proc sql noprint;
			select count(*) into: n_obs from &amp;amp;cur_ds.;
		quit;
		%put *** Dataset #&amp;amp;_i (&amp;amp;cur_ds) has: &amp;amp;n_obs Observations;

		/*----------------------------------------------------------------------------------
			Delete if empty 
	  	  ----------------------------------------------------------------------------------*/
		%if %eval(&amp;amp;n_obs + 0) =0 %then %do;
			%put *** Deleteing empty table: &amp;amp;cur_ds;
			proc sql noprint;
				drop table &amp;amp;cur_ds;
			quit;
		%end;

	%end;

	/*----------------------------------------------------------------------------------
		Clean list file &amp;amp; reload user options 
	  ----------------------------------------------------------------------------------*/
	proc sql noprint;
		drop table work._ds_list;
	quit;

	options &amp;amp;user_source &amp;amp;user_notes;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 24 May 2020 09:27:40 GMT</pubDate>
    <dc:creator>Assaf_Attas</dc:creator>
    <dc:date>2020-05-24T09:27:40Z</dc:date>
    <item>
      <title>_delete_empty_tables</title>
      <link>https://communities.sas.com/t5/SAS-Users-Group-in-Israel/delete-empty-tables/m-p/650146#M29</link>
      <description>&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;לפעמים מצטברות בספרייה מסוימת לא מעט טבלאות אשר אינן מכילות תצפיות..&lt;/P&gt;&lt;P&gt;המאקרו הבא משמש למחיקה גורפת של כל הטבלאות הריקות תחת ספרייה מסוימת.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro _delete_empty_tables(my_lib);

	%macro dummy;%mend dummy;

	/* Obtain option and temporarily turn off */
	%local user_source user_notes;
	%let user_source=%sysfunc(getoption(source));
	%let user_notes =%sysfunc(getoption(notes));

	option nosource nonotes;

	/*----------------------------------------------------------------------------------
		Declare local variables 
	  ----------------------------------------------------------------------------------*/
	%local _n_ds _i cur_ds cur_dm n_obs;

	/*----------------------------------------------------------------------------------
		Prepare list of all datasets in library 
	  ----------------------------------------------------------------------------------*/
	proc contents data=&amp;amp;my_lib.._all_ noprint nodetails directory out= work._ds_list (where=(MEMTYPE='DATA' and memname ne '_DS_LIST'));run;
	proc sort data= work._ds_list (keep=libname memname) nodupkeys;by libname memname;run;

	/*----------------------------------------------------------------------------------
		Determine number of datasets 
	  ----------------------------------------------------------------------------------*/
	proc sql noprint;
		select count(*) into: _n_ds
		from _ds_list;
	quit;
	%put *** Libref: "&amp;amp;my_lib" Contains: &amp;amp;_n_ds datasets;
	%put ***;

	/*----------------------------------------------------------------------------------
		Itterate on all tables 
	  ----------------------------------------------------------------------------------*/
	%do _i=1 %to &amp;amp;_n_ds;

		/*----------------------------------------------------------------------------------
			Point single table 
	  	  ----------------------------------------------------------------------------------*/
		data _null_;
			rec_num=&amp;amp;_i;
			set _ds_list point=rec_num;
			call symput("cur_ds",cats(libname,'.',memname));
			call symput("cur_dm",strip(memname));
			stop;
		run;

		/*----------------------------------------------------------------------------------
			Count observations in table 
	  	  ----------------------------------------------------------------------------------*/
		proc sql noprint;
			select count(*) into: n_obs from &amp;amp;cur_ds.;
		quit;
		%put *** Dataset #&amp;amp;_i (&amp;amp;cur_ds) has: &amp;amp;n_obs Observations;

		/*----------------------------------------------------------------------------------
			Delete if empty 
	  	  ----------------------------------------------------------------------------------*/
		%if %eval(&amp;amp;n_obs + 0) =0 %then %do;
			%put *** Deleteing empty table: &amp;amp;cur_ds;
			proc sql noprint;
				drop table &amp;amp;cur_ds;
			quit;
		%end;

	%end;

	/*----------------------------------------------------------------------------------
		Clean list file &amp;amp; reload user options 
	  ----------------------------------------------------------------------------------*/
	proc sql noprint;
		drop table work._ds_list;
	quit;

	options &amp;amp;user_source &amp;amp;user_notes;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 May 2020 09:27:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Users-Group-in-Israel/delete-empty-tables/m-p/650146#M29</guid>
      <dc:creator>Assaf_Attas</dc:creator>
      <dc:date>2020-05-24T09:27:40Z</dc:date>
    </item>
  </channel>
</rss>

