pobel 发表于 2015-9-28 10:10 
我用的是9.3 32位。
9.4可以么?
因为EXCEL单元格有255个字符的长度限制,所以根据不同windows系统、office设置来判断不同的情况。最好的方法是通过中介来转换XLSX和XLS格式的文件。
下面的方法可以通过CSV格式文件为中介,进行EXCEL to SAS的转换
- /*input*/ filename workbook "D:\downloads\test.xls";
- /*output*/ libname txtout "D:\test\";
- data Sheets(keep=text);
- /* gather info */
- length workbook txtout script filevar command $256;
- workbook = pathname('WORKBOOK');
- txtout = pathname('TXTOUT');
- script = catx('\',pathname('WORK'),'SHEETS2TXT.vbs');
- filevar = script;
-
- /* write the script */
- file dummy1 filevar=filevar;
- put 'Const ' workbook=$quote256.;
- put 'Const ' txtout=$quote256.;
- put 'Const xlCSV = 6';
-
- put 'Set objExcel = CreateObject("Excel.Application")';
- *put 'Set objExcel = GetObject(, "Excel.Application")';
- put 'With objExcel';
- put +3 '.Visible = False';
- put +3 '.DisplayAlerts = False';
- put +3 'Set objWorkbook = .Workbooks.Open(workbook)';
- put +3 'i = 0';
- put +3 'Set colSheets = .WorkSheets';
- put +3 'For Each objSheet In colSheets';
- put +6 'i = i + 1';
- put +6 'WScript.echo i & " " & txtout & "\" & objsheet.name & ".csv"';
- put +6 'objSheet.SaveAs txtout & "\" & objSheet.name & ".csv", xlCSV';
- put +6 'Next';
- put +3 '.Application.Quit';
- put +3 'End With';
-
- /* close the script file by opening another, not used */
- filevar = catx('\',pathname('WORK'),'DUMMY.vbs');
- file dummy1 filevar=filevar;
-
- /* look at the script, not necessary but may be useful */
- infile dummy2 filevar=script end=eof;
- do while(not eof);
- input;
- putlog _infile_;
- end;
-
- /* call the script */
- command = catx(' ','cscript',quote(strip(script)),'//nologo');
- infile dummy3 pipe filevar=command end=eof truncover;
- do while(not eof);
- input text $3000.;
- output;
- putlog _infile_;
- end;
- stop;
- run;
-
-
- proc import datafile="d:\test\sheet1.csv" out=outdata dbms=csv replace;
- run;
复制代码