左加入 returns 个空格
Left join returns blanks
我执行了左连接,其中左 table 有 500,000 个观察值。在某些情况下,左连接对于 Business_Line = "Retail" 是成功的,而下一个观察结果留空,这是为什么?
我使用的代码:
proc sql;
create table joined2 as
select a.*
,b.Join1
,b.Join2
,b.Join3
from joined as a
left join Sasdata.Assumptions as b
on a.Business_Line = b.Business_Line;
quit;
两个table长得像
data joined;
input Business_Line $;
datalines;
Retail
Retail
Retail
Business
Business
;
run;
要加入的 table 看起来像
data sasdata.assumptions;
input Business_Line $ Join1 Join2 Join3;
datalines;
Retail 10% 10% 10%
Business 20% 10% 5%
;
run;
当前结果 table 看起来像
business_line join1 join2 join3
Retail 10% 10% 10%
Retail . . .
Business 20% 10% 5%
Business . . .
示例代码未演示该问题。
确实,当实际 business_lines 值为 'Retail'
或 Business
时,join1-join3
的缺失值不会发生。您得到的结果是 3x1 行的 Retail 和 2x1 行的 Business。
当左侧 table 中的连接键在右侧 table 中没有相应的匹配项时,就会出现缺失值。如果变量被格式化,这可能似乎在 SAS 中发生。
假设 business_line 是一个具有格式化值
的整数
proc format;
value line
101 = 'Retail'
102 = 'Retail'
103 = 'Retail'
201 = 'Business'
202 = 'Business'
;
更新数据 business_line
data joined;
input Business_Line;
format Business_Line line.;
datalines;
101
102
102
201
202
run;
data assumptions;
input Business_Line Join1 Join2 Join3;
format Business_Line line.;
datalines;
101 10 10 10
201 20 10 5
run;
具有一些不匹配的基础值的联接
proc sql;
create table joined2 as
select a.*
,b.Join1
,b.Join2
,b.Join3
from joined as a
left join Assumptions as b
on a.Business_Line = b.Business_Line;
quit;
options nocenter; ods listing;
proc print data=joined2;
run;
结果显示缺失值
Business_
Obs Line Join1 Join2 Join3
1 Retail 10 10 10
2 Retail . . .
3 Retail . . .
4 Business 20 10 5
5 Business . . .
我执行了左连接,其中左 table 有 500,000 个观察值。在某些情况下,左连接对于 Business_Line = "Retail" 是成功的,而下一个观察结果留空,这是为什么?
我使用的代码:
proc sql;
create table joined2 as
select a.*
,b.Join1
,b.Join2
,b.Join3
from joined as a
left join Sasdata.Assumptions as b
on a.Business_Line = b.Business_Line;
quit;
两个table长得像
data joined;
input Business_Line $;
datalines;
Retail
Retail
Retail
Business
Business
;
run;
要加入的 table 看起来像
data sasdata.assumptions;
input Business_Line $ Join1 Join2 Join3;
datalines;
Retail 10% 10% 10%
Business 20% 10% 5%
;
run;
当前结果 table 看起来像
business_line join1 join2 join3
Retail 10% 10% 10%
Retail . . .
Business 20% 10% 5%
Business . . .
示例代码未演示该问题。
确实,当实际 business_lines 值为 'Retail'
或 Business
时,join1-join3
的缺失值不会发生。您得到的结果是 3x1 行的 Retail 和 2x1 行的 Business。
当左侧 table 中的连接键在右侧 table 中没有相应的匹配项时,就会出现缺失值。如果变量被格式化,这可能似乎在 SAS 中发生。
假设 business_line 是一个具有格式化值
的整数proc format;
value line
101 = 'Retail'
102 = 'Retail'
103 = 'Retail'
201 = 'Business'
202 = 'Business'
;
更新数据 business_line
data joined;
input Business_Line;
format Business_Line line.;
datalines;
101
102
102
201
202
run;
data assumptions;
input Business_Line Join1 Join2 Join3;
format Business_Line line.;
datalines;
101 10 10 10
201 20 10 5
run;
具有一些不匹配的基础值的联接
proc sql;
create table joined2 as
select a.*
,b.Join1
,b.Join2
,b.Join3
from joined as a
left join Assumptions as b
on a.Business_Line = b.Business_Line;
quit;
options nocenter; ods listing;
proc print data=joined2;
run;
结果显示缺失值
Business_
Obs Line Join1 Join2 Join3
1 Retail 10 10 10
2 Retail . . .
3 Retail . . .
4 Business 20 10 5
5 Business . . .