全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
6179 6
2005-05-26
When merging two tables, you can say merge a(in=ina) b(in=inb) ; and check to determine if values are coming in from table a and b. Is there something similar in PROC SQL when joining two tables?
二维码

扫码加我 拉你入群

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

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

全部回复
2005-5-26 21:19:00

应该可以对指定字段用case语句进行替换

如case a when '' 替换为表中另一字段

when 'ss'

else

二维码

扫码加我 拉你入群

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

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

2007-2-9 09:14:00

记得我用过一个不同的做法,等我找一下!

二维码

扫码加我 拉你入群

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

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

2007-2-9 20:18:00

proc sql ;

create table ab as

select

*

from a ina ,b inb

where ina.unikey=ina.unikey;

quit;

[此贴子已经被作者于2007-2-9 20:21:19编辑过]

二维码

扫码加我 拉你入群

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

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

2007-2-9 20:21:00

that sql is the same as following code.

data ab;

merge a (in = ina )

b (in = inb );

by unikey ;

if a and b ;

run;

二维码

扫码加我 拉你入群

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

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

2007-2-23 05:28:00

You have two ways to do it:

1. Use 'case' function to create a new variable, 'case' is really similar like 'if ... then' in your datastep.

2. Use 'coalesce' with OUTER JOINS (full join, left join, right join) operations:

coalesce (a.id, 0) will change all missing values or unmatched values of a.id as 0.

coalesce (b.id, 9999) will change all unmatched or missing value of b.id as 9999.

data a;

input id age;

cards;

3 12

4 5

5 35

6 20

7 11

8 20

;

run;

data b;

input id gender $;

cards;

1 F

2 M

4 M

6 F

7 M

10 F

11 M

;

run;

***METHOD 1****;

proc sql;

select a.*, b.gender,

case when a.id>0 then 1 else 0 end as ina,

case when b.id>0 then 1 else 0 end as inb

from a full join b

on a.id=b.id;

quit;

***MATHOD 2****;

proc sql;

select a.*, b.gender, coalesce(a.id, 0) as ina, coalesce (b.id,9999) as inb

from a full join b

on a.id=b.id;

quit;

[此贴子已经被作者于2007-2-23 5:33:31编辑过]

二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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