全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1944 4
2013-04-08
我需要合并两组数据,但是id中存在空值,使用proc sql会将所有空值也合并在一起:
proc sql;
create table mf.data as
select a.*,b.*
from mf.data_raw2 a left join mf.mf_index b on a.stkcd=b.stkcd
and a.fyear=b.fyear;
quit;

也就是说stkcd在两个表中都是存在空值的,现在有两个问题:
1)如何写程序使得两个表中的stkcd不为空时再进行合并。
2)如何drop掉mf_index中的stkcd和fyear使得sas不出现warning。
非常感谢!
二维码

扫码加我 拉你入群

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

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

全部回复
2013-4-8 10:49:07
以下代码没有经过测试,楼主可以试一下。

proc sql;
create table mf.data(drop=stkcd1 fyear1) as
select a.*,b.*
from mf.data_raw2 a left join mf.mf_index(rename=(stkcd=stkcd1 fyear=fyear1)) b
on ^missing(a.stkcd)
and
a.stkcd=b.stkcd1
and a.fyear=b.fyear1;
quit;
二维码

扫码加我 拉你入群

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

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

2013-4-8 11:03:56
pobel 发表于 2013-4-8 10:49
以下代码没有经过测试,楼主可以试一下。

proc sql;
谢谢您!我使用你的代码得到结果了。
我自己这样写:
proc sql;
create table mf.data as
select a.*,b.*
from mf.data_raw2 (where=(missing(stkcd)=0))a left join mf.mf_index(where=(missing(stkcd)=0)) b on a.stkcd=b.stkcd
and a.fyear=b.fyear;
quit;也得到了结果。但是写的很麻烦。谢谢!
二维码

扫码加我 拉你入群

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

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

2013-4-8 11:14:00
如果要一个 ID 是不是可以这样

data test1;
input ID  v1 v2;
datalines;
1001 2 3
1003 4 5
1004 6 7
.       8 9
1008 9 10
; run;

data test2;
input ID  v3 v4;
datalines;
1001 2 3
1003 4 5
1004 6 7
.       8 9
1007 9 10
;
proc sql;
   select coalesce(a.id, b.id) as id, a.v1, a.v2, b.v3, b.v4
   from test1 a left join test2 b
   on a.id=b.id
   where a.id ^= . and b.id ^=.;
quit;

results
id v1 v2 v3 v4
1001 2 3 2 3
1003 4 5 4 5
1004 6 7 6 7
二维码

扫码加我 拉你入群

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

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

2013-4-11 12:06:51
proc sort data=data_raw2  out a;by stkcd fyear;where stkcd not in("" .);run;
proc sort data=mf.mf_index out b;by stkcd fyear;where stkcd not in("" .);run;
data c;
merge a b;
by stkcd fyear;
run;
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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