要在读取原始数据文件时获得更高级别的控制,应考虑使用数据步骤,例如:
data want;
infile datalines4 dlm = ';' dsd;
input
id : $char25.
v1 : $char10.
v2 : 8.
;
datalines4;
301185964728506014850593;abc;123
30118596472850601485059;abcd;1234
3011859647285060148505;abcde;12345
;;;;
通过这种方式,您可以将ID指定为字符,这样数据将按照文件中显示的方式保存。
,
有一个SAS限制,一个数字可以有多大并且仍然保留精确的整数表示。 (基于尾数的二进制限制和双精度浮点值中的指数特征)
从“ SAS Companion for Windows”开始
Significant Digits and Largest Integer by Length for SAS Variables under Windows
Length Largest
in Integer Significant
Bytes Represented Exponential Digits
Exactly Notation Retained
------ ----------------------- ----------- -----------
3 8,192 213 3
4 2,097,152 221 6
5 536,870,912 229 8
6 137,438,953,472 237 11
7 35,184,372,088,832 245 13
8 9,007,199,254,740,992 253 15
无法使用IMPORT
过程直接指定列格式。
您可以调用该过程创建并修改的DATA Step源代码。
从文档文件“ Format-Specific Reference for the IMPORT and EXPORT Procedures” Delimited Files
在SAS中处理定界文件
当您使用PROC IMPORT读取逗号分隔的文件,制表符分隔的文件或其他定界文件时,该过程默认情况下会执行以下操作:
…
- 使用INPUT语句创建DATA步骤
- 将所有代码提交给DATA步骤编译器,然后由后者执行代码。
...
如果在过程运行后需要修改代码,请在生成的DATA步骤中发出RECALL命令(或按F4键)。此时,您可以在INFILE语句中添加或删除选项,并自定义数据的INFORMAT,FORMAT和INPUT语句。
因此步骤将
- 提交
Proc IMPORT
,输出零行。
此步骤唯一需要的是过程生成的源代码
- 打开一个新的编辑窗口(即菜单“查看/增强的编辑器”)
- 在命令栏中发出
RECALL
命令(或在菜单Run / Recall Last Submit中运行)
- 编辑召回的源代码
-删除限制器where=(1=0))
-将INFORMAT
从best32.
更改为$32.
-删除相应的FORMAT
语句
- 提交修改后的代码
示例:
使用太大的整数创建示例数据集,然后IMPORT
filename myfile temp;
data _null_;
file myfile;
put "one;two;three";
put "1;2;3";
put "301185964728506014850593;301185964728506014850594;301185964728506014850595";
put "301185964728506014850593;301185964728506014850594;301185964728506014850595";
put "301185964728506014850593;301185964728506014850594;301185964728506014850595";
put "301185964728506014850593;301185964728506014850594;301185964728506014850595";
put "301185964728506014850593;301185964728506014850594;301185964728506014850595";
put "301185964728506014850593;301185964728506014850594;301185964728506014850595";
run;
proc import
file=myfile
dbms=dlm
replace
out=myimport(where=(1=0) /* output limiter */
;
delimiter=';';
run;
调用SAS源代码,对其进行编辑并重新提交
/**********************************************************************
* PRODUCT: SAS
* VERSION: 9.4
* CREATOR: External File Interface
* DATE: 07NOV19
* DESC: Generated SAS Datastep Code
* TEMPLATE SOURCE: (None Specified.)
***********************************************************************/
data WORK.MYIMPORT
/*(where=(1=0)) */ /* <------ remove limiter */
;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
infile MYFILE delimiter = ';' MISSOVER DSD lrecl=32767 firstobs=2 ;
informat one $32. ; /* <-------- change informats */
informat two $32. ;
informat three $32. ;
/* format one best12. ;*/ /* <--------- remove format statements */
/* format two best12. ;*/
/* format three best12. ;*/
input
one
two
three
;
if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */
run;
产生数据集
Obs one two three
1 1 2 3
2 301185964728506014850593 301185964728506014850594 301185964728506014850595
3 301185964728506014850593 301185964728506014850594 301185964728506014850595
4 301185964728506014850593 301185964728506014850594 301185964728506014850595
5 301185964728506014850593 301185964728506014850594 301185964728506014850595
6 301185964728506014850593 301185964728506014850594 301185964728506014850595
7 301185964728506014850593 301185964728506014850594 301185964728506014850595
本文链接:https://www.f2er.com/3146060.html