楼主: rpg163
6007 8

求助:SAS 读入数据,第一行缺失时默认为$1. [推广有奖]

  • 1关注
  • 0粉丝

已卖:3份资源

教授

20%

还不是VIP/贵宾

-

威望
0
论坛币
3478 个
通用积分
30.4075
学术水平
2 点
热心指数
9 点
信用等级
3 点
经验
3531 点
帖子
207
精华
0
在线时间
2199 小时
注册时间
2007-3-24
最后登录
2024-11-9

楼主
rpg163 发表于 2011-5-3 21:38:27 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
RT,在使用SAS读入CSV数据时,有些数据第一列缺失,后面其实是有数据的,但此时SAS就默认为$1.的格式,结果后面的数据也没有办法读入,不知有什么方法可以解决这个问题。
谢谢
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:读入数据 什么方法 求助 数据 SAS 缺失

回帖推荐

qiuya 发表于6楼  查看完整内容

It shouldn`t actually happen unless some specific characters or missing value occur at first row. I think you may need to give out the examples as we could do more for you. I give you a tricky when importing the CSV file into SAS. For example, I got a CSV with below components: Using Proc Import Wizard first import that CSV file back to SAS, save the defaulted program somewhere ...

本帖被以下文库推荐

沙发
sas_user 发表于 2011-5-3 22:42:53
读一个文件好像没问题啊。如果是整列缺失,sas定义的长度为$1,如果是列的一部分缺失,长度比最长的字节还多1. sas9.1.3. 楼主是要同时读入多个文件吗?

藤椅
junuylia 发表于 2011-5-4 06:50:10
这是因为SAS有一个默认的最大读入行,改大点儿就行了,比如
  1. infile 'ozone.dat' missover linesize=100;
复制代码
已有 1 人评分热心指数 收起 理由
crackman + 1 鼓励积极发帖讨论

总评分: 热心指数 + 1   查看全部评分

板凳
rpg163 发表于 2011-5-4 12:21:50
2# sas_user
谢谢。
是读入一个文件,但我的读入的时候不知为什么都是类似情况都读成了$1. 可能与CSV有关,如果是EXCEL不会出现这一情况。但由于数据量有点大,就放在了1个CSV里。但不知为什么会这样

报纸
rpg163 发表于 2011-5-4 12:24:33
3# junuylia
谢谢
我试一下,不过不太明白这个命令,MISSOVER LINSIZE= 是指定缺失观测的变量的长度吗?是否可以指定数值/字符型?

地板
qiuya 发表于 2011-5-4 12:59:05
rpg163 发表于 2011-5-3 21:38
RT,在使用SAS读入CSV数据时,有些数据第一列缺失,后面其实是有数据的,但此时SAS就默认为$1.的格式,结果后面的数据也没有办法读入,不知有什么方法可以解决这个问题。
谢谢
It shouldn`t actually happen unless some specific characters or missing value occur at first row. I think you may need to give out the examples as we could do more for you.

I give you a tricky when importing the CSV file into SAS.

For example, I got a CSV with below components:

invid

subjid

phqtotal

mde

10

1001

3

MDE-

10

1002

14

MDE+

10

1003

4

MDE-

10

1004

12

MDE+




Using Proc Import Wizard first import that CSV file back to SAS, save the defaulted program somewhere. It will be something looks like this:

  1. PROC IMPORT OUT= WORK.example
  2.      DATAFILE= "C:\example.csv"
  3.      DBMS=CSV REPLACE;
  4.      GETNAMES=YES;
  5.      DATAROW=2;
  6. RUN;
复制代码


However, we could also get a better way and more customized way to import the CSV file!

Go to the log tab, You should see something like this in the Log tab:

  1. data WORK.example ;
  2.     %let _EFIERR_ = 0; /* set the ERROR detection macro variable */  
  3.     infile 'C:\example.csv' delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
  4.     informat invid best32. ;
  5.     informat _subjid best32. ;
  6.     informat _phqtotal best32. ;
  7.     informat _mde $4. ;
  8.     format invid best12. ;
  9.     format _subjid best12. ;
  10.     format _phqtotal best12. ;
  11.     format _mde $4. ;
  12.      input
  13.      invid
  14.     _subjid
  15.     _phqtotal
  16.     _mde $
  17.     ;
  18.    if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */
  19. run;
复制代码


Well, this is actually how SAS operating inside of the System by this import procedure.

You could copy over the above part SAS code back to use. The most benefit by using this set of code is you could change the format / informat/ length / character or numeric easily! And you can`t realy do that when using "Proc import" code as I show in the first block!

I hope that helps!

7
qiuya 发表于 2011-5-4 13:00:00
If you interested, try the code and you will have a better idea with what I mean here :-)

8
rpg163 发表于 2011-5-5 14:52:10
6# qiuya
谢谢。关于缺失的问题,的确是由于第一行数据缺失。
以前是觉得变量太多,用informat format 一个个设定过于麻烦。
不过目前使用的第二种方法。

9
zhenglaiyi 发表于 2011-5-26 12:34:46
在读取多个文件的时候碰到过这个问题,一个文件没有~

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

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