楼主: pobel
5675 16

Proc Import 不能完全读取超过255个字符的单元格内容 [推广有奖]

11
pobel 在职认证  发表于 2015-9-28 10:48:24
godxh 发表于 2015-9-28 10:36
xls的方法如下
多谢,这个可以用。
请设置一个1500论坛币的回复,我来购买。

12
lyfyb99 在职认证  发表于 2015-9-28 10:53:16
用import只是读取excel的方法之一, 有时libname更灵活,如下语句,可对xls 和 xlsx同时有效,并且很容易解决字符串被截断的问题。libname后即可像读取SAS dataset 一样打开excel....
输入的SAS code显示有问题,只好贴图


Capture.JPG (16.59 KB)

Capture.JPG

13
pobel 在职认证  发表于 2015-9-28 10:53:22
yongyitian 发表于 2015-9-28 10:41
Problem Note 46472: Character strings can be truncated at 255 or 1024 characters when importing Exce ...
多谢,好像程序的解决方法就只有dbms=xlsx

14
godxh 在职认证  发表于 2015-9-28 10:54:16
pobel 发表于 2015-9-28 10:10
我用的是9.3 32位。
9.4可以么?
因为EXCEL单元格有255个字符的长度限制,所以根据不同windows系统、office设置来判断不同的情况。最好的方法是通过中介来转换XLSX和XLS格式的文件。
下面的方法可以通过CSV格式文件为中介,进行EXCEL to SAS的转换
  1. /*input*/  filename workbook "D:\downloads\test.xls";
  2. /*output*/ libname  txtout   "D:\test\";

  3. data Sheets(keep=text);
  4.    /* gather info */
  5.    length workbook txtout script filevar command $256;
  6.    workbook = pathname('WORKBOOK');
  7.    txtout   = pathname('TXTOUT');
  8.    script   = catx('\',pathname('WORK'),'SHEETS2TXT.vbs');
  9.    filevar  = script;

  10.    /* write the script */
  11.    file dummy1 filevar=filevar;
  12.    put 'Const ' workbook=$quote256.;
  13.    put 'Const ' txtout=$quote256.;
  14.    put 'Const xlCSV = 6';

  15.    put 'Set objExcel = CreateObject("Excel.Application")';
  16.    *put 'Set objExcel = GetObject(, "Excel.Application")';
  17.    put 'With objExcel';
  18.    put +3 '.Visible = False';
  19.    put +3 '.DisplayAlerts = False';
  20.    put +3 'Set objWorkbook  = .Workbooks.Open(workbook)';
  21.    put +3 'i = 0';
  22.    put +3 'Set colSheets = .WorkSheets';
  23.    put +3 'For Each objSheet In colSheets';
  24.    put +6   'i = i + 1';
  25.    put +6   'WScript.echo i & " " & txtout & "\" & objsheet.name & ".csv"';
  26.    put +6   'objSheet.SaveAs txtout & "\" & objSheet.name & ".csv", xlCSV';
  27.    put +6   'Next';
  28.    put +3 '.Application.Quit';
  29.    put +3 'End With';

  30.    /* close the script file by opening another, not used */
  31.    filevar = catx('\',pathname('WORK'),'DUMMY.vbs');
  32.    file dummy1 filevar=filevar;

  33.    /* look at the script, not necessary but may be useful */
  34.    infile dummy2 filevar=script end=eof;
  35.    do while(not eof);
  36.       input;
  37.       putlog _infile_;
  38.       end;

  39.    /* call the script */
  40.    command = catx(' ','cscript',quote(strip(script)),'//nologo');
  41.    infile dummy3 pipe filevar=command end=eof truncover;
  42.    do while(not eof);
  43.       input text $3000.;
  44.       output;
  45.       putlog _infile_;
  46.       end;
  47.    stop;
  48. run;


  49. proc import datafile="d:\test\sheet1.csv" out=outdata dbms=csv replace;
  50. run;
复制代码


15
godxh 在职认证  发表于 2015-9-28 10:57:46
pobel 发表于 2015-9-28 10:48
多谢,这个可以用。
请设置一个1500论坛币的回复,我来购买。
购买吧。。。哈哈
Sample 1.jpg (37.67 KB, 需要: 1500 个论坛币)

16
pobel 在职认证  发表于 2015-9-28 11:14:50
lyfyb99 发表于 2015-9-28 10:53
用import只是读取excel的方法之一, 有时libname更灵活, ...
您好,这样读取之后,变量长度是改变了,但是值还是255个。

17
pobel 在职认证  发表于 2015-9-28 11:15:25
godxh 发表于 2015-9-28 10:57
购买吧。。。哈哈
已购买。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-29 12:56