楼主: playmore
5942 7

请问如下的infile语句问题在哪里 [推广有奖]

已卖:1645份资源

学科带头人

2%

还不是VIP/贵宾

-

TA的文库  其他...

R相关

经济学相关

金融工程

威望
1
论坛币
16356 个
通用积分
8.6697
学术水平
372 点
热心指数
394 点
信用等级
341 点
经验
15297 点
帖子
1194
精华
1
在线时间
1332 小时
注册时间
2007-1-11
最后登录
2025-12-1

初级学术勋章 初级热心勋章 中级热心勋章

楼主
playmore 发表于 2011-10-20 17:00:15 |AI写论文
20论坛币
我想用infile的方法导入如附件所示的数据,代码如下:

  1. data have;
  2. infile 'e:\data.txt' dsd dlm=',' firstobs=3 truncover noprint;
  3. input DATE:YYMMN6. RI1-RI11 IND1-IND24;
  4. format DATE YYMMN6.;
  5. run;
复制代码

但是导入到SAS中IND8到IND24列的数据无法导入
如果去掉truncover的话,除IND8外所有变量全能导入,但观测值只能导入单号的,不能导入双号的

我不清楚是不是原始数据的行末还有逗号的原因,因为原始数据不方便修改,所以还请问有没有解决的办法

谢谢

data.txt (85.14 KB)

最佳答案

关键词:infile file NFI truncover format input 全能
playmore邀请您访问ChinaTeX论坛!!!进入ChinaTeX论坛

沙发
yugao1986 发表于 2011-10-20 17:00:16
try this one:
  1. data have;
  2. infile 'c:\temp\data.txt' dsd delimiter= '2c0d'x  missover lrecl= 32767  firstobs=3 ;
  3. input DATE:YYMMN6. RI1-RI11 IND1-IND24 ;
  4. format DATE YYMMN6.;
  5. run;
复制代码
三人行必有我师

藤椅
playmore 发表于 2011-10-21 09:43:38
yugao1986 发表于 2011-10-20 17:00
try this one:
你好,昨天晚上我自己在网上搜了下,也发现了有个lrecl的设定,我当时设到1000就好了。还是要多谢你啊。

还有请问下你设置的delimiter中'2c0d'x代表哪个字符啊?为什么不用','呢?
playmore邀请您访问ChinaTeX论坛!!!进入ChinaTeX论坛

板凳
yugao1986 发表于 2011-10-21 10:16:58
ASCII,这里可能是进制的不同,帮助文档里有这么一段话:“Note:   Any time a text file originates from anywhere other than the local encoding environment, it might be necessary to specify the ENCODING= option on either EBCDIC or ASCII environments.

For example, when you read an EBCDIC text file on an ASCII platform, it is recommended that you specify the ENCODING= option in the INFILE statement. However, if you use the DSD and DLM options in the INFILE statement, the ENCODING= option is a requirement because these options require certain characters in the session encoding (such as quotation marks, commas, and blanks).

The use of encoding-specific informats should be reserved for use with true binary files. That is, files that contain both character and noncharacter fields.  
三人行必有我师

报纸
yugao1986 发表于 2011-10-21 10:29:58
看看下面的文档,还有相关帖子:
http://support.sas.com/techsup/technote/ts642.html
https://bbs.pinggu.org/thread-1212283-1-1.html
https://bbs.pinggu.org/thread-702705-1-1.html
下面是小例子:
data _null_;
  x='2c0d'x ;
  put x $ascii3.;
run;

三人行必有我师

地板
spssone 发表于 2011-10-25 14:46:44
楼主提个问题,数据文件还收费,怎么回事啊?

7
playmore 发表于 2011-10-25 14:51:46
spssone 发表于 2011-10-25 14:46
楼主提个问题,数据文件还收费,怎么回事啊?
我的附件没有收费啊
有可能你是在高峰时期下载的
那个时候是论坛收的流量费
不是我收的
playmore邀请您访问ChinaTeX论坛!!!进入ChinaTeX论坛

8
yanan9256 发表于 2011-10-25 16:22:55
yugao1986 发表于 2011-10-20 17:00
try this one:
我看书上 有个 pad选项
lrecl规定每行的长度 pad选项使得不够长度的那行数据后面用空格补全
没有pad选项时,sas会到下一行读数据直至读到规定行长度,这样可能出错

请注意这个问题
sashelp
pad options,infile statement
PAD|NOPAD specifies whether records that are read from an external data set are padded with blanks up to the length specified in the LRECL= option.

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

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