Sql 如何使用sas中的数据步骤从特定数据集中保留列
我有两个表,它们具有相同属性的相同列。我想从两个表中选择该列和其他列。范例Sql 如何使用sas中的数据步骤从特定数据集中保留列,sql,sas,Sql,Sas,我有两个表,它们具有相同属性的相同列。我想从两个表中选择该列和其他列。范例 table_1 ID | column_1 | column_2 1 | col_1 | col_2 2 | col_1 | col_2 3 | col_1 | col_2 table_2 ID | column_3 | column_4 4 | col_3 | col_4 5 | col_3 | col_4 6 | col_3 | col_4 我想创建
table_1
ID | column_1 | column_2
1 | col_1 | col_2
2 | col_1 | col_2
3 | col_1 | col_2
table_2
ID | column_3 | column_4
4 | col_3 | col_4
5 | col_3 | col_4
6 | col_3 | col_4
我想创建一个表作为
Required
ID | column_1 | column_4
1 | col_1 | col_4
2 | col_1 | col_4
3 | col_1 | col_4
我想使用数据步骤来完成它
data required;
set table_1 table_2;
keep ID column_1 column_4;
run;
但它给了我6排
我可以使用proc-sql获取我的表
proc sql noprint;
create table required as
select t1.Id, t1.column_1, t2.column_4
from table_1 as t1, table_2 as t2;
quit;
我希望对数据步骤执行相同的操作如果使用
集
,则数据集将按顺序读取。如果要逐个记录合并数据集,请使用合并
。通常,您会使用BY
语句根据一些关键变量组合记录。但是如果您不使用BY语句,SAS将按顺序合并记录
还要注意变量名冲突。两个输入都有一个ID
变量。看起来您只想保留第一个数据集中的数据。您可以使用KEEP=
dataset选项告诉SAS要从数据集中包含哪些变量
data required;
merge table_1 (keep=id column_1) table_2 (keep=column_4);
run;
你的加入条件是什么?是否要将表1中id=n的行与表2中id=n+3的行进行匹配?还是要完全忽略
id
?