SAS中文论坛

标题: 在sas中如何对数据集进行等值连接 [打印本页]

作者: shiyiming    时间: 2004-4-16 08:18
标题: 在sas中如何对数据集进行等值连接
假设数据集dataset1有a b c三个字段,dataset2有d e f三个字段,要根据字段a和字段d对两个数据集进行等值连接生成dataset3,dataset3包含a b c e f五个字段,在sas中如何实现
作者: shiyiming    时间: 2004-4-16 08:49
你的意思是说数据集1的a和数据集2的d取值是相同的?

如果是这样,就可将此两个变量作为排序变量进行数据的拼接。首先要将数据集2的d更名为a,然后编写如下程序。

proc sort data=data1;
by a;
run;
proc sort data=data2;
by a;
run;
data data3;
merge data1 data2;
by a;
run;
作者: shiyiming    时间: 2004-4-16 12:09
用proc sql试试

[quote:81df6]
[color=blue:81df6]proc sql;
  create table dataset3 as
  select a.a, a.b,a.c, b.e,b.f
  from dataset1 as a, dataset2 as b
  where a.a= b.d;
quit;[/color:81df6]

[/quote:81df6]
作者: shiyiming    时间: 2004-4-16 13:39
proc sort data=dataset1;
by a;
proc sort data=dataset2;
by d;
data dataset3;
merge dataset1 dataset2(rename=(d=a));
by a;
run;
作者: shiyiming    时间: 2004-4-16 14:52
标题: ◎~◎
没看出yees的比student的好在哪里, <!-- s:( --><img src="{SMILIES_PATH}/icon_sad.gif" alt=":(" title="Sad" /><!-- s:( -->
作者: shiyiming    时间: 2004-4-16 22:35
I would like to bring an attention to the difference between PROC SQL and SAS data set MERGE.  If the data in two data sets are one to one match, quite often, MERGE and SQL JOIN get same thing, but if it is not the case, the results are more likely different.  SAS MERGE statement has a lof of hiden rules which are often ignored by many users, it can be dangerous.  There are many papers discussing the differences, I can not list them here.  I sugguest people try to construct two data sets with duplicated keys and postential missing values, then try to play them with MERGE and SQL JOINs (inner, outter, left and right).  You will get some taste.  In general, I always prefer SQL than MERGE, since the logic is standard.
作者: shiyiming    时间: 2004-4-23 16:50
标题: 感谢
本来想偷懒不顶了,后来看了别的论坛一个斑竹的帖子提到提问的人都是不劳而获,应该回贴表示感谢,同时也是对别人劳动成果的尊重,觉得很有道理。
多谢各位高手的讲解 <!-- s:lol: --><img src="{SMILIES_PATH}/icon_lol.gif" alt=":lol:" title="Laughing" /><!-- s:lol: -->




欢迎光临 SAS中文论坛 (http://mysas.net/forum/) Powered by Discuz! X3.2