楼主: Trevor
5719 6

[讨论]SAS PROC SQL [推广有奖]

  • 1关注
  • 4粉丝

副教授

26%

还不是VIP/贵宾

-

TA的文库  其他...

Probability NewOccidental

RapidMiner NewOccidental

Machine Learning

威望
1
论坛币
3388 个
通用积分
0.4274
学术水平
25 点
热心指数
17 点
信用等级
24 点
经验
5231 点
帖子
414
精华
2
在线时间
176 小时
注册时间
2005-5-4
最后登录
2024-4-7

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
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?
二维码

扫码加我 拉你入群

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

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

关键词:proc sql ROC sql something determine 讨论 SAS proc sql

回帖推荐

sakunamary 发表于4楼  查看完整内容

proc sql ; create table ab as select * from a ina ,b inb where ina.unikey=ina.unikey; quit; [此贴子已经被作者于2007-2-9 20:21:19编辑过]

zzheng722 发表于6楼  查看完整内容

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 ...

本帖被以下文库推荐

沙发
carvel 发表于 2005-5-26 21:19:00 |只看作者 |坛友微信交流群

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

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

when 'ss'

else

使用道具

藤椅
dido099 发表于 2007-2-9 09:14:00 |只看作者 |坛友微信交流群

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

使用道具

板凳
sakunamary 发表于 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编辑过]

已有 1 人评分经验 论坛币 收起 理由
bakoll + 10 + 10 热心帮助其他会员

总评分: 经验 + 10  论坛币 + 10   查看全部评分

我sas故我在

使用道具

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

我sas故我在

使用道具

地板
zzheng722 发表于 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编辑过]

已有 1 人评分经验 论坛币 收起 理由
bakoll + 5 + 10 热心帮助其他会员

总评分: 经验 + 5  论坛币 + 10   查看全部评分

使用道具

7
zzheng722 发表于 2007-2-23 05:40:00 |只看作者 |坛友微信交流群

1) Full join is the same as:

data new;

merge a (in=ina) b(in=inb);

by id;

if ina or inb;

run;

proc sql;

create table new as

select *

from a full join b

on a.id=b.id;

quit;

2) LEFT JOIN is the same as:

data new;

merge a (in=ina) b(in=inb);

by id;

if ina ;

run;

proc sql;

create table new as

select *

from a left join b

on a.id=b.id;

quit;

3) RIGHT JOIN is the same as:

data new;

merge a (in=ina) b(in=inb);

by id;

if inb;

run;

proc sql;

create table new as

select *

from a right join b

on a.id=b.id;

quit;

使用道具

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

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

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

GMT+8, 2024-4-26 18:32