全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
2386 6
2011-10-24
data b;
input name $ sex $ region $ date yymmdd10. money;
label name='姓名' sex='性别' region='地区' date='日期' money='金额';
format date yymmdd10.;
cards;
章文 男 华东 1996-3-20 1099
亡国铭 男 华东 1996-5-19 39
童子敏 女 华北 1996-1-5 986
刘念新 男 东北 1997-10-1 3581
刘思今 女 华北 1997-4-1 659
关绍 女 东北 1996-11-5 358
赵霞 女 东北 1998-9-6 2010
;
run;
proc print;
run;

读入的时候 例如 最后一个观测 2010 读成了 10。我知道是位宽的问题 该怎么设置日期的读入格式啊?请指教
当我将日期补成 1998-09-06的时候 读入就正常了
二维码

扫码加我 拉你入群

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

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

全部回复
2011-10-24 22:16:09
第2行date后面加上冒号:
input name $ sex $ region $ date: yymmdd10. money;
二维码

扫码加我 拉你入群

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

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

2011-10-24 22:26:15
huanglunbu 发表于 2011-10-24 22:16
第2行date后面加上冒号:
input name $ sex $ region $ date: yymmdd10. money;
谢谢 我对冒号理解有错误 我把冒号设置到 name后面了 我以为对整句都有效呢
二维码

扫码加我 拉你入群

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

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

2011-10-25 10:03:32
In SAS an informat on input statement implies a variable type and positional length on the input file. It is only applied to a fixed length file. Fixed length text file is usually a output of IBM applications.

The best way for a beginner is to defined length, informat, format, and label clearly, see example below.

Or one can define all of them with attrib statement.  

data b;
length name $8 sex $2 region $4 date money 8;
informat date yymmdd10. ;
format date date9.;
label name='姓名' sex='性别' region='地区' date='日期' money='金额';

input name  sex  region  date  money;


cards;
章文 男 华东 1996-3-20 1099
亡国铭 男 华东 1996-5-19 39
童子敏 女 华北 1996-1-5 986
刘念新 男 东北 1997-10-1 3581
刘思今 女 华北 1997-4-1 659
关绍 女 东北 1996-11-5 358
赵霞 女 东北 1998-9-6 2010
;

proc print;
run;
二维码

扫码加我 拉你入群

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

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

2011-10-25 16:03:28
bobguy 发表于 2011-10-25 10:03
In SAS an informat on input statement implies a variable type and positional length on the input fil ...
谢谢您的指点

那么我又有了一个新的疑惑

当我直接在input语句中对 date变量定义 格式的时候 yymmdd10. 最后一个变量money 有些就会读入出错
而您的程序中 规范定义了length informat format 之后读入的数据就没有问题。
这两者有什么区别呢??麻烦您指点
二维码

扫码加我 拉你入群

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

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

2011-10-27 10:40:45
yanan9256 发表于 2011-10-25 16:03
谢谢您的指点

那么我又有了一个新的疑惑
There are a couple of knowledge point here,
1) fixed length data file vs. variable length data file

2) input statement with an informat implied variable type + length taken from data. Your input statement style also implies space delimiter.

yymmdd10. has length 10

record: 赵霞 女 东北 1998-9-6 2010
length of 1998-9-6 2=10
the left 010 = 10 as of numeric representation.

if you change 2010 to 2110, the money will show 110.

Why SAS takes 1998-9-6 2 and correctly interprets it as 1998-9-6 is beyond my knowledge. My guess is a space matters here. Sorry!

二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群