【学习总结】merge的用法

来源:互联网 发布:qq头像素材源码 编辑:程序博客网 时间:2024/06/18 16:02
/*一对一合并,不需要by语句*/data a;merge resdat.class resdat.stk000001;run;

(朱世武,126)

 

/*匹配合并必须有by语句*/data a;merge resdat.stk000001 (keep=date clpr rename=(clpr=clpr000001))resdat.stk000002 (keep=date clpr rename=(clpr=clpr000002));by date;run;

(朱世武,126)

/*使用数据集选项(in=)*/data a5;                                                                                                          input x y$ @@; cards;                1 a 1 b 1 c 2 x 3 y                ; run;    data a6; input x y$ @@; cards;      1 aa 2 xx 4 yy;           run;   data a56;    merge a5(in=ina) a6(in=inb);     by x;     in_a=ina;     in_b=inb; run; /*The IN=data set option is a flag to the variable of the BY group instead of any other variables.*//*Because the variable x(not y) is in the BY group,so although the values(b and c) of y in table5 do not exist in table6, the flags do not change.*/
/*如果merge的数据集中有相同变量名,那么merge后的变量值取merge语句中最右边数据集的那一个*/

(人大经济论坛,http://t.cn/zTHMUJM)

/*小训练,举一反三*//*建立测试数据集*/data test;input num $ age salary;datalines;01 28 620002 30 800001 29 750003 31 900005 32 1000008 26 7000;proc sort;by num;run;/*用merge语句取出id为01、03、08的记录*/data tmp1;input num$@@;datalines;01 03 08;proc sort;by num;run;data select;merge test(in=ind1) tmp1(in=ind2);in_a=ind1;in_b=ind2;by num;if in_a & in_b;run;

(自编)

原创粉丝点击