全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
9545 19
2012-08-01
悬赏 50 个论坛币 已解决
现有2.78G的csv格式数据

其中var1是形如“20110829”的字符串,有1999~2012的数据

需要按年把数据拆分开,分别保存,以便接下来的处理。

求程序代码


在论坛网友的帮助下,问题基本解决了,以下是我自己的代码:
data cd;
infile 'D:\fdata\cust_done.csv'
DLM = ','
DSD
missover
firstobs=2;
input date$ exch$ id variety$ del$ price$ vol$ short$ tb$ close$ fee method$ time$
pervol force$;
run;

proc print data=cd (obs = 10);
run;
data cd1;
set cd;
year=substr(date,1,4);
run;
data  cd1999 cd2000 cd2001 cd2002 cd2003 cd2004 cd2005 cd2006 cd2007 cd2008 cd2009
cd2010 cd2011 cd2012;
set cd1;
select(year);
when ('1999') output cd1999;
when ('2000') output cd2000;
when ('2001') output cd2001;
when ('2002') output cd2002;
when ('2003') output cd2003;
when ('2004') output cd2004;
when ('2005') output cd2005;
when ('2006') output cd2006;
when ('2007') output cd2007;
when ('2008') output cd2008;
when ('2009') output cd2009;
when ('2010') output cd2010;
when ('2011') output cd2011;
when ('2012') output cd2012;
end;
run;

最佳答案

ziyenano 查看完整内容

比如说 infile cards; input x1 x2 x3; cards; 1 2 1 2 3 ; 默认的是flowover,第一行x1读取1,x2读取2,x3会读取第二行的1;后x1继续读取第二行的2,x3读取3; 结果为: x1 x2 x3 1 2 1 2 3 . 很多时候这不是我们要的结果;infile 设置missover; 第一行x1读取1,x2读取2,x3自动设为缺失值; 结果为: x1 x2 x3 1 2 . 1 2 3
二维码

扫码加我 拉你入群

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

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

全部回复
2012-8-1 07:46:57
比如说
infile cards;
input x1 x2 x3;
cards;
1 2
1 2 3
;
默认的是flowover,第一行x1读取1,x2读取2,x3会读取第二行的1;后x1继续读取第二行的2,x3读取3;
结果为:
x1 x2 x3
1   2   1
2   3   .
很多时候这不是我们要的结果;infile 设置missover;
第一行x1读取1,x2读取2,x3自动设为缺失值;
结果为:
x1 x2 x3
1   2    .
1   2   3


二维码

扫码加我 拉你入群

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

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

2012-8-1 07:58:50
按位读取前四位,开关,写入不同数据集
二维码

扫码加我 拉你入群

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

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

2012-8-1 08:58:30
data  year1999  year.2000  year2001  year2002  year2003  year2004
  year2005  year2006  year2007   year2008   year2009  year2010
year2011 year2012;
set dataname;
if substr(var11,1,4)=’1999’  then output  year1999;
if substr(var11,1,4)=’2000’  then output  year2000;
if substr(var11,1,4)=’2001’  then output  year2001;
if substr(var11,1,4)=’2002’  then output  year2002;
if substr(var11,1,4)=’2003’  then output  year2003;
if substr(var11,1,4)=’2004’  then output  year2004;
if substr(var11,1,4)=’2005’  then output  year2005;
if substr(var11,1,4)=’2006’  then output  year2006;
if substr(var11,1,4)=’2007’  then output  year2007;
if substr(var11,1,4)=’2008’  then output  year2008;
if substr(var11,1,4)=’2009’  then output  year2009;
if substr(var11,1,4)=’2010’  then output  year2010;
if substr(var11,1,4)=’2011’  then output  year2011;
if substr(var11,1,4)=’2012’  then output  year2012;
run;
我的办法比较笨拙,供参考
二维码

扫码加我 拉你入群

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

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

2012-8-1 09:39:03
Good
二维码

扫码加我 拉你入群

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

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

2012-8-1 10:02:30
楼主要拆分成SAS数据集,还是CSV文件
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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