楼主: dxystata
1245 11

如何得到这样的数据集 [推广有奖]

11
pobel 在职认证  发表于 2014-10-20 07:45:58 |只看作者 |坛友微信交流群
dxystata 发表于 2014-10-19 22:55
如何再保留c a b对应的oid 和x2的取值?谢谢!
oid  x2
1    aaa
data ccc;
   set aaa end=last;
   by site name notsorted;

        if _n_=1 then call execute("data ddd(keep=oid x2 name site: drop=site); merge ");
        if first.site then call execute(cats("ccc(where=(site=",site,") rename=(_x1=site",site,"))"));
        if last then call execute(" ccc(where=(^missing(x2)) keep=name_order x2 oid) ; by name_order; run;");

        if first.site then name_order=0;
    if first.name then do; _x1=catx(" ",x1); name_order+1; end;
    else if not first.name then _x1=catx(" ",_x1,x1);
    if last.name;
    retain _x1 ;
run;

使用道具

12
pobel 在职认证  发表于 2014-10-20 07:55:51 |只看作者 |坛友微信交流群
dxystata 发表于 2014-10-19 22:22
data ccc;
   set aaa end=last;
   by site name notsorted;
总体的思路就是下面两步:
1. 合并每个name在某个site内的值,确保每个site+name只有一条记录;
2. 选出每个site的记录,并merge到一起。

由于第二步需要知道有多少个site以及每个site的值,这样在计算第一步的同时,第二步的代码也可以做出来。
代码放到CALL EXECUTE()里,这些代码就会在data CCC之后运行。
已有 1 人评分经验 学术水平 热心指数 收起 理由
dxystata + 50 + 2 + 2 精彩帖子

总评分: 经验 + 50  学术水平 + 2  热心指数 + 2   查看全部评分

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-8 11:51