<?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 Write and execute VBA macro in SAS EG in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606061#M175941</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've currently created a SAS program that outputs an XLS file, that i later on open in Excel to apply a macro to it that removes empty lines.&lt;/P&gt;
&lt;P&gt;Is there any way I could skip the step where I open it in Excel and directly execute the macro in SAS?&lt;/P&gt;
&lt;P&gt;Note that I've looked for many hours and even asked a SAS consultant how I could do this directly in SAS but unfortunately I have to use this VBA macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
    <pubDate>Thu, 21 Nov 2019 09:29:04 GMT</pubDate>
    <dc:creator>polpel</dc:creator>
    <dc:date>2019-11-21T09:29:04Z</dc:date>
    <item>
      <title>Write and execute VBA macro in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606061#M175941</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've currently created a SAS program that outputs an XLS file, that i later on open in Excel to apply a macro to it that removes empty lines.&lt;/P&gt;
&lt;P&gt;Is there any way I could skip the step where I open it in Excel and directly execute the macro in SAS?&lt;/P&gt;
&lt;P&gt;Note that I've looked for many hours and even asked a SAS consultant how I could do this directly in SAS but unfortunately I have to use this VBA macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2019 09:29:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606061#M175941</guid>
      <dc:creator>polpel</dc:creator>
      <dc:date>2019-11-21T09:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: Write and execute VBA macro in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606062#M175942</link>
      <description>&lt;P&gt;Could you give an example of the output? Removing empty lines, at first glance, seems like a trivial operation in SAS.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2019 09:32:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606062#M175942</guid>
      <dc:creator>jvdl</dc:creator>
      <dc:date>2019-11-21T09:32:56Z</dc:date>
    </item>
    <item>
      <title>Re: Write and execute VBA macro in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606063#M175943</link>
      <description>&lt;P&gt;Hey, thanks for your quick reply!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First of, here's the VBA code I need to run:&lt;/P&gt;
&lt;P&gt;Sub DeleteAllEmptyRows()&lt;BR /&gt;Dim LastRowIndex As Integer&lt;BR /&gt;Dim RowIndex As Integer&lt;BR /&gt;Dim UsedRng As Range&lt;BR /&gt;&lt;BR /&gt;Set UsedRng = ActiveSheet.UsedRange&lt;BR /&gt;LastRowIndex = UsedRng.Row - 1 + UsedRng.Rows.Count&lt;BR /&gt;Application.ScreenUpdating = False&lt;BR /&gt;&lt;BR /&gt;For RowIndex = LastRowIndex To 1 Step -1&lt;BR /&gt;If Application.CountA(Rows(RowIndex)) = 0 Then&lt;BR /&gt;Rows(RowIndex).Delete&lt;BR /&gt;End If&lt;BR /&gt;Next RowIndex&lt;BR /&gt;&lt;BR /&gt;Application.ScreenUpdating = True&lt;BR /&gt;End Sub&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've attached both current and wanted output files! Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2019 09:38:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606063#M175943</guid>
      <dc:creator>polpel</dc:creator>
      <dc:date>2019-11-21T09:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: Write and execute VBA macro in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606066#M175944</link>
      <description>&lt;P&gt;Please post the SAS code that creates the Excel spreadsheet.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2019 10:10:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606066#M175944</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-21T10:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: Write and execute VBA macro in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606070#M175947</link>
      <description>&lt;P&gt;here it is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data age;
	input ctr name $ age;
	cards;
123 paul 52
123 peter 41
123 jack 16
123 caroline 12
;
run;

data height;
	input ctr name $ height;
	cards;
123 paul 185
123 peter 176
123 jack 172
123 caroline 168
;
run;

ODS EXCEL file = "path/to/file.xls";
ODS EXCEL options (sheet_name="data" sheet_interval="none" index="yes" flow="tables");
ODS SELECT ALL;

ODS TEXT='***AGE_OPEN';
PROC PRINT data=age noobs;
QUIT;
ODS TEXT='***AGE_CLOSE';
ODS TEXT='***HEIGHT_OPEN';
PROC PRINT data=height noobs;
QUIT;
ODS TEXT='***HEIGHT_CLOSE';

ODS EXCEL CLOSE;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Nov 2019 10:19:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606070#M175947</guid>
      <dc:creator>polpel</dc:creator>
      <dc:date>2019-11-21T10:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: Write and execute VBA macro in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606104#M175962</link>
      <description>&lt;P&gt;This may be a very elaborate way around it, but I guess it's still quicker than having to run a VBA script after exporting. I would also like to see a solution which, perhaps, addresses the empty lines generated by PROC PRINT directly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the interim, however, import the created XLSX file into a SAS dataset, remove the empty lines, and export it again. Add this to the end of your existing code and it should remove the empty lines for you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* ===== Import the newly created XLSX file into SAS and remove blanks ===== */
%let excelfilename = %str(~/file.xlsx);

proc import datafile="&amp;amp;excelfilename." DBMS=xlsx out=temp1 replace;
	getnames = no;
	sheet = 'data';
run;

data temp2;
	set temp1;

	/*Loop over all the columns in a row, if a non-missing column exists*/
	/*the row will not be deleted*/
	array allnums _numeric_;
	do over allnums;
		if not missing(allnums) then contains_data = 1;
	end;

	array allchars _character_;
	do over allchars;
		if not missing(allchars) then contains_data = 1;
	end;

	/*Delete rows with all missing values*/
	if not(contains_data) then delete;

	drop contains_data;
run;

proc export data=temp2 dbms=xlsx outfile="&amp;amp;excelfilename." replace;
	putnames = no;
	sheet = 'data';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Nov 2019 12:56:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606104#M175962</guid>
      <dc:creator>jvdl</dc:creator>
      <dc:date>2019-11-21T12:56:22Z</dc:date>
    </item>
    <item>
      <title>Re: Write and execute VBA macro in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606105#M175963</link>
      <description>&lt;P&gt;I was able to remove one empty line (between two text lines) by using an additional option:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ODS EXCEL options (sheet_name="data" sheet_interval="none" index="yes" flow="tables" suppress_bylines="yes");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but the empty lines created by each separate proc print remain. This seems to be an inherent "problem" with ODS EXCEL.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2019 12:59:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606105#M175963</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-21T12:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: Write and execute VBA macro in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606114#M175965</link>
      <description>hey man, thanks I'll try that. Quick question: would this work with a .xls file?</description>
      <pubDate>Thu, 21 Nov 2019 13:22:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606114#M175965</guid>
      <dc:creator>polpel</dc:creator>
      <dc:date>2019-11-21T13:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: Write and execute VBA macro in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606115#M175966</link>
      <description>&lt;P&gt;Probably, otherwise just change your file extension to .xlsx and see what happens &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2019 13:22:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606115#M175966</guid>
      <dc:creator>jvdl</dc:creator>
      <dc:date>2019-11-21T13:22:51Z</dc:date>
    </item>
    <item>
      <title>Re: Write and execute VBA macro in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606131#M175975</link>
      <description>I mean a .xls file in the proc export&lt;BR /&gt;I made an error in the code I sent, it's supposed to be path/to/file.xls</description>
      <pubDate>Thu, 21 Nov 2019 13:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606131#M175975</guid>
      <dc:creator>polpel</dc:creator>
      <dc:date>2019-11-21T13:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Write and execute VBA macro in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606135#M175977</link>
      <description>&lt;P&gt;&amp;nbsp;You could try just switching DBMS=XLSX to DBMS=XLS (or DBMS=EXCEL depending on backwards compatibility) and then changing the file extension accordingly.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2019 14:07:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606135#M175977</guid>
      <dc:creator>jvdl</dc:creator>
      <dc:date>2019-11-21T14:07:55Z</dc:date>
    </item>
    <item>
      <title>Re: Write and execute VBA macro in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606139#M175978</link>
      <description>&lt;P&gt;You can create a VBS file, automatically execute it from SAS and delete it afterwards:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro executeVBS(xmlFileName=%str(C:\Temp\Temp1),vbsFileName=%str(C:\Temp\classtest3.vbs));
   data _null_;    
      file "&amp;amp;vbsFileName";
      put " Set oXL = CreateObject(""Excel.Application"")";
      put " Set FSO = CreateObject(""Scripting.FileSystemObject"")";
      put " Dim objWorkBook";
      put " oXL.Visible=False";
      put " oXL.DisplayAlerts = False";
      /*
      ...
      */
      put " oXL.ActiveWorkbook.SaveAs ""&amp;amp;xmlFileName.""";       
      put " oXL.DisplayAlerts = True";
      put " oXL.Quit";
      put " oXL.ErrorCheckingOptions.NumberAsText = False";
      put " Set oXL = Nothing";
      put " FSO.DeleteFile(""&amp;amp;vbsFileName""), DeleteReadOnly";   
      put " Set FSO = Nothing";
      put " Set objWorkBook = Nothing";
   run;
   data _null_;
      call system("""&amp;amp;vbsFileName"""); 
   run;
%mend executeVBS;
%executeVBS(xmlFileName=&amp;amp;createdFileName..xml,vbsFileName=&amp;amp;createdFileName.pivot.vbs);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Nov 2019 14:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606139#M175978</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2019-11-21T14:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: Write and execute VBA macro in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606165#M175988</link>
      <description>This works for an .xls file?</description>
      <pubDate>Thu, 21 Nov 2019 15:02:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606165#M175988</guid>
      <dc:creator>polpel</dc:creator>
      <dc:date>2019-11-21T15:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: Write and execute VBA macro in SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606166#M175989</link>
      <description>&lt;P&gt;Enterprise Guide always runs on Windows. But the SAS code you submit via EG could be running on some other operating system.&amp;nbsp; You probably need to make sure that the machine where SAS is running can run Excel.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2019 15:05:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-and-execute-VBA-macro-in-SAS-EG/m-p/606166#M175989</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-21T15:05:53Z</dc:date>
    </item>
  </channel>
</rss>

