楼主: lemonxinran
1686 4

当id存在空值时合并数据的处理 [推广有奖]

  • 0关注
  • 1粉丝

讲师

28%

还不是VIP/贵宾

-

威望
0
论坛币
1159 个
通用积分
6.3000
学术水平
1 点
热心指数
1 点
信用等级
1 点
经验
10334 点
帖子
188
精华
0
在线时间
599 小时
注册时间
2010-10-25
最后登录
2024-3-26

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
我需要合并两组数据,但是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。
非常感谢!
二维码

扫码加我 拉你入群

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

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

关键词:合并数据 left join proc sql warning Select

沙发
pobel 在职认证  发表于 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;
和谐拯救危机

使用道具

藤椅
lemonxinran 发表于 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;也得到了结果。但是写的很麻烦。谢谢!

使用道具

板凳
yongyitian 发表于 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

使用道具

报纸
chaosxiao 发表于 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;

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-2 03:02