<?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: How to delete empty datasets before exporting to excel? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-empty-datasets-before-exporting-to-excel/m-p/820622#M323922</link>
    <description>&lt;P&gt;Your comments says you have dataset with the list of datasets and number of observations, but you don't say what variables have that information.&amp;nbsp; Let's assume they are called DSNAME and NOBS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc export 
  data = WORK.UT_LIST
  dbms = xlsx
  outfile="/home/&amp;amp;_CLIENTUSERID./UT_ERR_LIST.xlsx"
  replace
;
  sheet='UT_LIST';
run;

data _null_;
  set WORK.UT_LIST ;
  where nobs &amp;gt; 0 ;
  call execute(catx(' '
  ,'proc export data=',dsname,'dbms = xlsx'
  ,'outfile=',quote("/home/&amp;amp;_CLIENTUSERID./UT_ERR_LIST.xlsx")
  ,'replace;'
  ,'sheet=',quote(trim(dsname))
  ,';run;'
  ));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notice how no macro code is needed at all.&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jun 2022 02:18:23 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-06-28T02:18:23Z</dc:date>
    <item>
      <title>How to delete empty datasets before exporting to excel?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-empty-datasets-before-exporting-to-excel/m-p/820621#M323921</link>
      <description>&lt;P&gt;I have this code which creates a bunch of tables and then using a macro exports them to an excel file. All the datasets are created to the WORK library and then exported. I want to know how I can edit my code to only export the datasets that have observations in them. Here is the macro I am using to export to excel:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro create_ut_xlsx; %macro _; %mend _;

	proc export 
	  data = WORK.UT_LIST /* UT_LIST is a table that shows all the other tables and how many observations they have */
	  dbms = xlsx
	  outfile="/home/&amp;amp;_CLIENTUSERID./UT_ERR_LIST.xlsx"
	  replace;
	  sheet='UT_LIST';
	run;

	%do n = 1 %to &amp;amp;UT_COUNT;
		%let CURR_UT_ID = %scan(%ut_list , &amp;amp;n, |);
		%put &amp;amp;CURR_UT_ID.;
	
		proc export 
		  data = WORK.&amp;amp;CURR_UT_ID. 
		  dbms = xlsx 
		  outfile="/home/&amp;amp;_CLIENTUSERID./UT_ERR_LIST.xlsx"
		  replace;
		  sheet="&amp;amp;CURR_UT_ID.";
		run;

		data _NULL_;
			if 0 then set WORK.&amp;amp;CURR_UT_ID. nobs = N;
			call symputx('CURR_UT_ID_NR_OF_ERRS', N);
			stop;
		run;
		%put In &amp;amp;CURR_UT_ID. the number of issues is &amp;amp;CURR_UT_ID_NR_OF_ERRS.;
		
		data _NULL_;
			if 0 then set WORK.&amp;amp;CURR_UT_ID. nobs = N;
			
		proc sql noprint;
			update UT_LIST set NR_ERR = &amp;amp;CURR_UT_ID_NR_OF_ERRS.
			where UT_ID = "&amp;amp;CURR_UT_ID.";
		quit;
	%end;

	proc export 
	  data = WORK.UT_LIST
	  dbms = xlsx
	  outfile="/home/&amp;amp;_CLIENTUSERID./UT_ERR_LIST.xlsx"
	  replace;
	  sheet='UT_LIST';
	run;


%mend create_ut_xlsx;

%create_ut_xlsx;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Please let me know how I can accomplish this and if you require more info.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2022 02:04:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-empty-datasets-before-exporting-to-excel/m-p/820621#M323921</guid>
      <dc:creator>stormblaster98</dc:creator>
      <dc:date>2022-06-28T02:04:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete empty datasets before exporting to excel?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-empty-datasets-before-exporting-to-excel/m-p/820622#M323922</link>
      <description>&lt;P&gt;Your comments says you have dataset with the list of datasets and number of observations, but you don't say what variables have that information.&amp;nbsp; Let's assume they are called DSNAME and NOBS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc export 
  data = WORK.UT_LIST
  dbms = xlsx
  outfile="/home/&amp;amp;_CLIENTUSERID./UT_ERR_LIST.xlsx"
  replace
;
  sheet='UT_LIST';
run;

data _null_;
  set WORK.UT_LIST ;
  where nobs &amp;gt; 0 ;
  call execute(catx(' '
  ,'proc export data=',dsname,'dbms = xlsx'
  ,'outfile=',quote("/home/&amp;amp;_CLIENTUSERID./UT_ERR_LIST.xlsx")
  ,'replace;'
  ,'sheet=',quote(trim(dsname))
  ,';run;'
  ));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notice how no macro code is needed at all.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2022 02:18:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-empty-datasets-before-exporting-to-excel/m-p/820622#M323922</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-28T02:18:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete empty datasets before exporting to excel?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-empty-datasets-before-exporting-to-excel/m-p/820624#M323924</link>
      <description>&lt;P&gt;Sorry Im a bit new to SAS programming so Im not sure what you mean by&amp;nbsp; "what variables have that information". I'll try to further explain my program and what it does hopefully that helps. Basically I have a proc sql statement which creates tables 1-78 called UT_01, UT_02, etc. These tables are created to the WORK library along with UT_LIST which has the UT_ID (Table names), NR_ERR (number of observations), UT_TEXT (Descriptor). When NR_ERR is 0 the dataset is empty, and so that UT_ID table should not be exported. Hope that helps.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2022 02:52:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-empty-datasets-before-exporting-to-excel/m-p/820624#M323924</guid>
      <dc:creator>stormblaster98</dc:creator>
      <dc:date>2022-06-28T02:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete empty datasets before exporting to excel?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-empty-datasets-before-exporting-to-excel/m-p/820626#M323925</link>
      <description>&lt;P&gt;The code as posted by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; does what you request. Since you did not provide any details he used NOBS instead of NR_ERR and Dsname instead of UT_ID which are variable names in your UT_LIST data set from your description.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hint: for future questions start with a description of your data set. Better is an actual example data and best is for the example to be in the form of data step code so we have some to test.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2022 03:30:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-empty-datasets-before-exporting-to-excel/m-p/820626#M323925</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-28T03:30:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete empty datasets before exporting to excel?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-delete-empty-datasets-before-exporting-to-excel/m-p/820630#M323929</link>
      <description>&lt;P&gt;Yes, I was able to get it working with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;code so thank you for that Tom.&lt;BR /&gt;&lt;BR /&gt;Thanks for the feedback will remember that for future posts.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2022 03:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-delete-empty-datasets-before-exporting-to-excel/m-p/820630#M323929</guid>
      <dc:creator>stormblaster98</dc:creator>
      <dc:date>2022-06-28T03:34:58Z</dc:date>
    </item>
  </channel>
</rss>

