楼主: Trevor
6556 6

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

  • 1关注
  • 4粉丝

已卖:1100份资源

副教授

26%

还不是VIP/贵宾

-

TA的文库  其他...

Probability NewOccidental

RapidMiner NewOccidental

Machine Learning

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

楼主
Trevor 发表于 2005-5-26 09:59:00 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
<FONT color=#1a42e6 size=4>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?</FONT>
二维码

扫码加我 拉你入群

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

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

关键词: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
<P>应该可以对指定字段用case语句进行替换</P>
<P>如case a when ''    替换为表中另一字段</P>
<P>              when 'ss'</P>
<P>               else</P>
<P>     </P>

藤椅
dido099 发表于 2007-2-9 09:14:00
<P>记得我用过一个不同的做法,等我找一下!</P>

板凳
sakunamary 发表于 2007-2-9 20:18:00
<P>proc sql ;</P>
<P>create table ab as </P>
<P>select  </P>
<P>    *</P>
<P>from a ina ,b inb </P>
<P>where ina.unikey=ina.unikey;</P>
<P>quit;</P>

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

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

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

我sas故我在

报纸
sakunamary 发表于 2007-2-9 20:21:00
<P>that sql is the same as following code.</P>
<P>data ab;</P>
<P>merge a (in = ina )</P>
<P>      b (in = inb );</P>
<P>by unikey ;</P>
<P>if a and b ;</P>
<P>run; </P>
我sas故我在

地板
zzheng722 发表于 2007-2-23 05:28:00
<P>You have two ways to do it:  </P>
<P>1. Use 'case' function to create a new variable, 'case' is really similar like 'if ... then' in your datastep.</P>
<P>2. Use 'coalesce' with OUTER JOINS (full join, left join, right join) operations: </P>
<P>coalesce (a.id, 0) will change all missing values or unmatched values of a.id as 0.</P>
<P>coalesce (b.id, 9999) will change all unmatched or missing value of b.id as 9999.</P>
<P><B><FONT face="Courier New" color=#000080 size=2>data</B></FONT><FONT face="Courier New" size=2> a;</P></FONT><FONT face="Courier New" color=#0000ff size=2>
<P>input</FONT><FONT face="Courier New" size=2> id age;</P></FONT><FONT face="Courier New" color=#0000ff size=2>
<P>cards</FONT><FONT face="Courier New" size=2>;</P>
<P>3 12</P>
<P>4 5</P>
<P>5 35</P>
<P>6 20</P>
<P>7 11</P>
<P>8 20</P>
<P>;</P></FONT><B><FONT face="Courier New" color=#000080 size=2>
<P>run</B></FONT><FONT face="Courier New" size=2>; </P></FONT><B><FONT face="Courier New" color=#000080 size=2>
<P>data</B></FONT><FONT face="Courier New" size=2> b;</P></FONT><FONT face="Courier New" color=#0000ff size=2>
<P>input</FONT><FONT face="Courier New" size=2> id gender $;</P></FONT><FONT face="Courier New" color=#0000ff size=2>
<P>cards</FONT><FONT face="Courier New" size=2>;</P>
<P>1 F</P>
<P>2 M</P>
<P>4 M</P>
<P>6 F</P>
<P>7 M</P>
<P>10 F</P>
<P>11 M</P>
<P>;</P></FONT><B><FONT face="Courier New" color=#000080 size=2>
<P>run</B></FONT><FONT face="Courier New" size=2>;</FONT></P>
<P><FONT face="Courier New" size=2>***METHOD 1****;<B><FONT face="Courier New" color=#000080 size=2></P>
<P>proc</B></FONT><FONT face="Courier New" size=2> </FONT><B><FONT face="Courier New" color=#000080 size=2>sql</B></FONT><FONT face="Courier New" size=2>;</P></FONT><FONT face="Courier New" color=#0000ff size=2>
<P>select</FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#008080 size=2>a.</FONT><FONT face="Courier New" size=2>*, b.gender, </P>
<P></FONT><FONT face="Courier New" color=#0000ff size=2>case</FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>when</FONT><FONT face="Courier New" size=2> a.id&gt;</FONT><B><FONT face="Courier New" color=#008080 size=2>0</B></FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>then</FONT><FONT face="Courier New" size=2> </FONT><B><FONT face="Courier New" color=#008080 size=2>1</B></FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>else</FONT><FONT face="Courier New" size=2> </FONT><B><FONT face="Courier New" color=#008080 size=2>0</B></FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>end</FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>as</FONT><FONT face="Courier New" size=2> ina,</P>
<P></FONT><FONT face="Courier New" color=#0000ff size=2>case</FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>when</FONT><FONT face="Courier New" size=2> b.id&gt;</FONT><B><FONT face="Courier New" color=#008080 size=2>0</B></FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>then</FONT><FONT face="Courier New" size=2> </FONT><B><FONT face="Courier New" color=#008080 size=2>1</B></FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>else</FONT><FONT face="Courier New" size=2> </FONT><B><FONT face="Courier New" color=#008080 size=2>0</B></FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>end</FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>as</FONT><FONT face="Courier New" size=2> inb</P></FONT><FONT face="Courier New" color=#0000ff size=2>
<P>from</FONT><FONT face="Courier New" size=2> a full join b</P>
<P>on a.id=b.id;</P></FONT><B><FONT face="Courier New" color=#000080 size=2>
<P>quit</B></FONT><FONT face="Courier New" size=2>;</FONT></P>
<P>***MATHOD 2****;</FONT><FONT face="Courier New" size=2></P></FONT><B><FONT face="Courier New" color=#000080 size=2>
<P>proc</B></FONT><FONT face="Courier New" size=2> </FONT><B><FONT face="Courier New" color=#000080 size=2>sql</B></FONT><FONT face="Courier New" size=2>;</P></FONT><FONT face="Courier New" color=#0000ff size=2>
<P>select</FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#008080 size=2>a.</FONT><FONT face="Courier New" size=2>*, b.gender, coalesce(a.id, </FONT><B><FONT face="Courier New" color=#008080 size=2>0</B></FONT><FONT face="Courier New" size=2>) </FONT><FONT face="Courier New" color=#0000ff size=2>as</FONT><FONT face="Courier New" size=2> ina, coalesce (b.id,9999</FONT><FONT face="Courier New" size=2>) </FONT><FONT face="Courier New" color=#0000ff size=2>as</FONT><FONT face="Courier New" size=2> inb</P></FONT><FONT face="Courier New" color=#0000ff size=2>
<P>from</FONT><FONT face="Courier New" size=2> a full join b</P>
<P>on a.id=b.id;</P></FONT><B><FONT face="Courier New" color=#000080 size=2>
<P>quit</B></FONT><FONT face="Courier New" size=2>;</P></FONT>

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

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

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

7楼
zzheng722 发表于 2007-2-23 05:40:00
<P>1) Full join is the same as:</P>
<P>data new;</P>
<P>merge a (in=ina) b(in=inb);</P>
<P>by id;</P>
<P>if ina or inb;</P>
<P>run;</P>
<P><FONT face="Courier New" color=#000000>proc sql;</FONT></P>
<P><FONT face="Courier New" color=#000000>create table new as</FONT></P>
<P><FONT face="Courier New" color=#000000>select *</FONT></P>
<P>from<FONT face="Courier New" size=2> a full join b</P>
<P>on a.id=b.id;</P></FONT><FONT face="Courier New" size=2>
<P><FONT color=#000000><STRONG>quit</STRONG></FONT></FONT><FONT face="Courier New" color=#000000 size=2><STRONG>;</STRONG></FONT></P>
<P>2) LEFT JOIN is the same as:</P>
<P>data new;</P>
<P>merge a (in=ina) b(in=inb);</P>
<P>by id;</P>
<P>if ina ;</P>
<P>run;</P>
<P><FONT face="Courier New" color=#000000>proc sql;</FONT></P>
<P><FONT face="Courier New" color=#000000>create table new as</FONT></P>
<P><FONT face="Courier New" color=#000000>select *</FONT></P>
<P><FONT color=#000000>from</FONT><FONT face="Courier New" size=2><FONT color=#000000> a left join b</FONT></P>
<P><FONT color=#000000>on a.id=b.id;</FONT></P></FONT><B><FONT face="Courier New" size=2>
<P><FONT color=#000000>quit</FONT></B></FONT><FONT face="Courier New" color=#000000 size=2>;</FONT></P>
<P>3) RIGHT JOIN is the same as:</P>
<P>data new;</P>
<P>merge a (in=ina) b(in=inb);</P>
<P>by id;</P>
<P>if inb;</P>
<P>run;</P>
<P><FONT face="Courier New" color=#000000>proc sql;</FONT></P>
<P><FONT face="Courier New" color=#000000>create table new as</FONT></P>
<P><FONT face="Courier New" color=#000000>select *</FONT></P>
<P>from<FONT face="Courier New" size=2> a right join b</P>
<P>on a.id=b.id;</P></FONT><B><FONT face="Courier New" color=#000080 size=2>
<P><FONT color=#000000>quit</FONT></B></FONT><FONT face="Courier New" color=#000000 size=2>;</FONT></P>

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

客服
GMT+8, 2026-12-4 12:46