<?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: Converting XML to XLSX - Ignoring Corrupt Files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-XML-to-XLSX-Ignoring-Corrupt-Files/m-p/490656#M128425</link>
    <description>&lt;P&gt;I think this is a very bad idea by the way.&lt;/P&gt;
&lt;P&gt;Excel is the worst possible format to hold data. There is no data type or metadata. It's a mess.&lt;/P&gt;
&lt;P&gt;I would strongly suggest that use zip&amp;nbsp;the XML files instead.&lt;/P&gt;
&lt;P&gt;They can then be&amp;nbsp;accessed directly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FILENAME ZIPFILE SASZIPAM "&amp;amp;path\archive.zip";

DATA newdata;
  INFILE ZIPFILE(data1.xml);
  INPUT @; 
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Aug 2018 22:22:25 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2018-08-28T22:22:25Z</dc:date>
    <item>
      <title>Converting XML to XLSX - Ignoring Corrupt Files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-XML-to-XLSX-Ignoring-Corrupt-Files/m-p/489285#M127725</link>
      <description>&lt;P&gt;To decrease file sizes, my company has standard code that exports files to XML format and then uses %convert_files() macro to convert XML to XLSX.&amp;nbsp; Basically, this macro will go to the specified directory (default parameter) and convert all XML files to the specified file type (ext parameter).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I run into a small issue where a SAS program might produce a "corrupt" file.&amp;nbsp; This is detected by the file size being 68 KB (a blank but non-corrupted file is 70 KB).&amp;nbsp; When such a file is found, this macro pauses and won't convert the files.&amp;nbsp; Even if later down the road this file is still&amp;nbsp;in the directory and a new non-corrupted file is produced, it won't convert even the valid files.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know VBscript, so can anyone tell me if I can modify the code below to delete any XML files of size 68 KB found before running through the directory and converting any other files?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options noxwait noxsync; 

%macro convert_files(default=,ext=);
      data _null_;
            file "'&amp;amp;default\temp.vbs'";
            put "set xlapp = CreateObject(""Excel.Application"")";
            put "set fso = CreateObject(""scripting.filesystemobject"")";
            put "set myfolder = fso.GetFolder(""&amp;amp;default"")";
            put "set myfiles = myfolder.Files";
            put "xlapp.DisplayAlerts = False";
            put " ";
            put "for each f in myfiles";
            put "  ExtName = fso.GetExtensionName(f)";
            put "  Filename= fso.GetBaseName(f)";
            put "    if ExtName=""&amp;amp;ext"" then";
            put "           set mybook = xlapp.Workbooks.Open(f.Path)"; 
            put "           xlapp.Visible = false";
            put "           mybook.SaveAs ""&amp;amp;default.\"" &amp;amp; Filename &amp;amp; "".xlsx"", 51";
            put "    End If";
            put "  Next";
            put "  mybook.Close";
            put "  xlapp.DisplayAlerts = True";
            /* Removes original files */
            put " FSO.DeleteFile(""&amp;amp;default\*.&amp;amp;ext""), DeleteReadOnly";
            put " xlapp.Quit";
            put " Set xlapp = Nothing";
            put " strScript = Wscript.ScriptFullName";
            put " FSO.DeleteFile(strScript)"; 
      run; 
 
      x "cscript ""&amp;amp;default\temp.vbs""";
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Aug 2018 14:43:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-XML-to-XLSX-Ignoring-Corrupt-Files/m-p/489285#M127725</guid>
      <dc:creator>djbateman</dc:creator>
      <dc:date>2018-08-23T14:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: Converting XML to XLSX - Ignoring Corrupt Files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-XML-to-XLSX-Ignoring-Corrupt-Files/m-p/489478#M127817</link>
      <description>&lt;P&gt;You'd be better off asking this on a Microsoft forum; People are not VBS experts here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having said that, a web search for&amp;nbsp;&amp;nbsp;&lt;FONT face="courier new,courier"&gt;vbs delete file by size&lt;/FONT&gt; &amp;nbsp;returns many replies, so there's probably no point even asking,&lt;/P&gt;</description>
      <pubDate>Fri, 24 Aug 2018 02:36:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-XML-to-XLSX-Ignoring-Corrupt-Files/m-p/489478#M127817</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-24T02:36:10Z</dc:date>
    </item>
    <item>
      <title>Re: Converting XML to XLSX - Ignoring Corrupt Files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-XML-to-XLSX-Ignoring-Corrupt-Files/m-p/490656#M128425</link>
      <description>&lt;P&gt;I think this is a very bad idea by the way.&lt;/P&gt;
&lt;P&gt;Excel is the worst possible format to hold data. There is no data type or metadata. It's a mess.&lt;/P&gt;
&lt;P&gt;I would strongly suggest that use zip&amp;nbsp;the XML files instead.&lt;/P&gt;
&lt;P&gt;They can then be&amp;nbsp;accessed directly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FILENAME ZIPFILE SASZIPAM "&amp;amp;path\archive.zip";

DATA newdata;
  INFILE ZIPFILE(data1.xml);
  INPUT @; 
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 22:22:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-XML-to-XLSX-Ignoring-Corrupt-Files/m-p/490656#M128425</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-28T22:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: Converting XML to XLSX - Ignoring Corrupt Files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-XML-to-XLSX-Ignoring-Corrupt-Files/m-p/490869#M128580</link>
      <description>&lt;P&gt;In case there is anyone else out there looking for this solution, I actually came across an article that helped me remove any files.&amp;nbsp; I know ChristNZ does not approve, but this is what works for what my company needs done.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The macro below will now find all "ext" files in the "default" directory, delete any that are &amp;lt;70KB (this is because XML files are corrupt files if they are 68KB and clean but empty at 70KB), and finally convert any "ext" files to XLSX.&amp;nbsp; I may be the only one to benefit from this, but now the information is out there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro convert_files(default=,ext=);
	data _null_;
		file "'&amp;amp;default\temp.vbs'";
		put "set xlapp = CreateObject(""Excel.Application"")";
		put "set fso = CreateObject(""scripting.filesystemobject"")";
		put "set myfolder = fso.GetFolder(""&amp;amp;default"")";
		put "set myfiles = myfolder.Files";
		put "xlapp.DisplayAlerts = False";
		put " ";
		put "for each f in myfiles";
		put "If f.Size &amp;lt; 70000 And fso.GetExtensionName(f)=""&amp;amp;ext"" Then";
		put "  f.Delete True";
		put "    End If";
		put "  Next";
		put " ";
		put "for each f in myfiles";
		put "  ExtName = fso.GetExtensionName(f)";
		put "  Filename= fso.GetBaseName(f)";
		put "    if ExtName=""&amp;amp;ext"" then";
		put "           set mybook = xlapp.Workbooks.Open(f.Path)"; 
		put "           xlapp.Visible = false";
		put "           mybook.SaveAs ""&amp;amp;default.\"" &amp;amp; Filename &amp;amp; "".xlsx"", 51";
		put "    End If";
		put "  Next";
		put "  mybook.Close";
		put "  xlapp.DisplayAlerts = True";
		/* Removes original files */
		put " FSO.DeleteFile(""&amp;amp;default\*.&amp;amp;ext""), DeleteReadOnly";
		put " xlapp.Quit";
		put " Set xlapp = Nothing";
		put " strScript = Wscript.ScriptFullName";
		put " FSO.DeleteFile(strScript)"; 
	run; 
 
	x "cscript ""&amp;amp;default\temp.vbs""";
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Aug 2018 14:45:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-XML-to-XLSX-Ignoring-Corrupt-Files/m-p/490869#M128580</guid>
      <dc:creator>djbateman</dc:creator>
      <dc:date>2018-08-29T14:45:35Z</dc:date>
    </item>
  </channel>
</rss>

