Created
October 25, 2017 15:53
-
-
Save statgeek/c51f58a009f8d315a200f34912e494b1 to your computer and use it in GitHub Desktop.
SAS - convert XML to XLSX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Sourced from here: | |
http://support.sas.com/kb/43/496.html | |
*/ | |
options noxwait noxsync; | |
%macro convert_files(default=,ext=); | |
data _null_; | |
file "'&default\temp.vbs'"; | |
put "set xlapp = CreateObject(""Excel.Application"")"; | |
put "set fso = CreateObject(""scripting.filesystemobject"")"; | |
put "set myfolder = fso.GetFolder(""&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=""&ext"" then"; | |
put " set mybook = xlapp.Workbooks.Open(f.Path)"; | |
put " xlapp.Visible = false"; | |
put " mybook.SaveAs ""&default.\"" & Filename & "".xlsx"", 51"; | |
put " End If"; | |
put " Next"; | |
put " mybook.Close"; | |
put " xlapp.DisplayAlerts = True"; | |
/* Removes original files */ | |
/*put " FSO.DeleteFile(""&default\*.&ext""), DeleteReadOnly";*/ | |
put " xlapp.Quit"; | |
put " Set xlapp = Nothing"; | |
put " strScript = Wscript.ScriptFullName"; | |
put " FSO.DeleteFile(strScript)"; | |
run; | |
x "cscript ""&default\temp.vbs"""; | |
%mend; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment