楼主: cysk1011
9736 19

[原创博文] SAS大数据量的排序、拆分、保存 [推广有奖]

  • 0关注
  • 0粉丝

本科生

52%

还不是VIP/贵宾

-

威望
0
论坛币
8332 个
通用积分
1.3500
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1099 点
帖子
49
精华
0
在线时间
129 小时
注册时间
2011-4-12
最后登录
2024-3-23

楼主
cysk1011 发表于 2012-8-1 07:46:56 |AI写论文
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
关键词:大数据 missover variety output infile

本帖被以下文库推荐

沙发
ziyenano 发表于 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


藤椅
zkymath 在职认证  发表于 2012-8-1 07:58:50 来自手机
按位读取前四位,开关,写入不同数据集

板凳
liuywustb 发表于 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;
我的办法比较笨拙,供参考

报纸
suzhzh 发表于 2012-8-1 09:39:03
Good

地板
ziyenano 发表于 2012-8-1 10:02:30
楼主要拆分成SAS数据集,还是CSV文件

7
cysk1011 发表于 2012-8-1 10:08:09
ziyenano 发表于 2012-8-1 10:02
楼主要拆分成SAS数据集,还是CSV文件
csv文件

现在基本弄好了,有一个细节问题,就是用import读入数据,有一个指标形如“1109”,sas会把它作为时间读入,并改变其格式。我希望仍然按字符的格式读入,该怎么办?

8
ziyenano 发表于 2012-8-1 10:40:31
cysk1011 发表于 2012-8-1 10:08
csv文件

现在基本弄好了,有一个细节问题,就是用import读入数据,有一个指标形如“1109”,sas会把它 ...
proc import会在log中,编译成数据步语句;修改数据步那个变量的informat format   然后运行数据步就可以了。

9
hamn 发表于 2012-8-1 10:42:45
cysk1011 发表于 2012-8-1 10:08
csv文件

现在基本弄好了,有一个细节问题,就是用import读入数据,有一个指标形如“1109”,sas会把它 ...
对这个指标定义成字符型即可。

10
hamn 发表于 2012-8-1 10:55:03
liuywustb 发表于 2012-8-1 08:58
data  year1999  year.2000  year2001  year2002  year2003  year2004
  year2005  year2006  year2007    ...
这个方法很好

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-19 20:13