Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何使用sas中的数据步骤从特定数据集中保留列_Sql_Sas - Fatal编程技术网

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