全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1337 5
2013-06-05
悬赏 200 个论坛币 已解决
请问高手,我有一组数据,可是这组数据里有一部分是重复的,我想把这组数据分成两组,一组是原来的数据,另一组是混进来的数据,请高手指点。

  y               x1            x2           x3             x4            x5            x6       x7
1.000        1.00        1.00        1.000        2.000        0.42        0.770        1.000
1.000        1.00        1.00        1.000        2.000        10.79      0.770        1.000
1.000        1.00        1.00        4.000        4.000        1.84        0.850        2.000
1.000        1.00        1.00        4.000        4.000        1.84        0.850        2.000
1.000        1.00        1.00        4.000        2.000        0.46        1.000        2.000
1.000        1.00        1.00        4.000        2.000        0.46        1.000        2.000
1.000        1.00        2.00        4.000        2.000        0.92        0.860        1.000
1.000        1.00        2.00        4.000        3.000        20.38      1.000        2.000
1.000        1.00        2.00        4.000        2.000        24.66       0.960        2.000
1.000        1.00        2.00        4.000        2.000        16.82       0.960        2.000
1.000        1.00        3.00        4.000        1.000        6.59        0.850        1.000
1.000        1.00        3.00        4.000        1.000        6.59        0.850        1.000
1.000        1.00        3.00        3.000        2.000        6.59        0.850        1.000
1.000        1.00        3.00        3.000        2.000        6.59        0.850        1.000
1.000        1.00        3.00        4.000        4.000        6.90        1.000        1.000
1.000        1.00        3.00        4.000        2.000        2.84        0.820        1.000
1.000        1.00        3.00        4.000        1.000        14.51      1.000        1.000
1.000        1.00        3.00        4.000        1.000        14.51       1.000        1.000
1.000        1.00        3.00        4.000        1.000        10.42       1.000        1.000
1.000        1.00        3.00        4.000        3.000        24.63        0.890        2.000
1.000        1.00        3.00        4.000        3.000        107.31      0.890        2.000
1.000        2.00        1.00        3.000        2.000        48.66        0.830        1.000
1.000        2.00        1.00        3.000        1.000        32.34        0.930        1.000
1.000        2.00        1.00        4.000        4.000        3.39          0.830        2.000
1.000        2.00        1.00        4.000        4.000        3.39          0.830        2.000
1.000        2.00        2.00        4.000        2.000        39.57        0.840        1.000
1.000        2.00        2.00        4.000        2.000        39.57        0.840        1.000
1.000        2.00        2.00        2.000        2.000        26.40        0.820        2.000
1.000        2.00        3.00        4.000        1.000        31.23        0.350        2.000
1.000        2.00        3.00        4.000        2.000        10.10        0.830        3.000
1.000        2.00        3.00        4.000        2.000        10.10        0.830        3.000
1.000        4.00        1.00        4.000        1.000        117.25      0.800        1.000
0.000        1.00        2.00        1.000        3.000        27.78        0.570        2.000
0.000        1.00        2.00        1.000        3.000        27.78        0.570        2.000
0.000        1.00        2.00        1.000        1.000        0.85          0.940        1.000
0.000        1.00        2.00        1.000        1.000        0.85         0.940        1.000
0.000        2.00        1.00        4.000        2.000        83.70        0.690        3.000
0.000        2.00        3.00        4.000        3.000        217.75      1.000        1.000
0.000        3.00        2.00        3.000        3.000        50.30        0.840        3.000
0.000        3.00        2.00        2.000        2.000        313.26       0.640        1.000
0.000        3.00        3.00        1.000        4.000        231.15       0.830        1.000
0.000        3.00        3.00        1.000        4.000        64.00         0.830        1.000
0.000        3.00        3.00        4.000        3.000        227.80       0.620        1.000
0.000        3.00        3.00        4.000        3.000        57.94         0.620        1.000
0.000        3.00        3.00        4.000        3.000        321.60       0.880        2.000
0.000        4.00        1.00        2.000        3.000        854.33        0.710        2.000
0.000        4.00        1.00        2.000        3.000        388.81        0.590        3.000
0.000        4.00        1.00        2.000        3.000        388.81        0.590        3.000
0.000        4.00        2.00        4.000        4.000        53.46         0.880        3.000
0.000        4.00        3.00        2.000        2.000        277.50        0.570        3.000
0.000        4.00        3.00        2.000        2.000        277.50        0.570        3.000
0.000        4.00        3.00        1.000        3.000        321.92        0.620        1.000
0.000        4.00        3.00        1.000        3.000        321.92        0.620        1.000


最佳答案

yongyitian 查看完整内容

可以简单一点 proc sort data=a; by y x1-x7; run; data original dups; set a; by y x1-x7; if first.x7 then output original; else output dups; run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-6-5 22:41:30
可以简单一点

proc sort data=a;
    by y x1-x7;
run;

data original dups;
     set a;
     by y x1-x7;
     if first.x7 then output original;
     else output dups;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-6-6 00:25:01
楼主看看这个是否满足你的要求~

data a;
input y x1 x2 x3 x4 x5 x6 x7;
cards;
1.000        1.00        1.00        1.000        2.000        0.42        0.770        1.000
1.000        1.00        1.00        1.000        2.000        10.79      0.770        1.000
1.000        1.00        1.00        4.000        4.000        1.84        0.850        2.000
1.000        1.00        1.00        4.000        4.000        1.84        0.850        2.000
1.000        1.00        1.00        4.000        2.000        0.46        1.000        2.000
1.000        1.00        1.00        4.000        2.000        0.46        1.000        2.000
1.000        1.00        2.00        4.000        2.000        0.92        0.860        1.000
1.000        1.00        2.00        4.000        3.000        20.38      1.000        2.000
1.000        1.00        2.00        4.000        2.000        24.66       0.960        2.000
1.000        1.00        2.00        4.000        2.000        16.82       0.960        2.000
1.000        1.00        3.00        4.000        1.000        6.59        0.850        1.000
1.000        1.00        3.00        4.000        1.000        6.59        0.850        1.000
1.000        1.00        3.00        3.000        2.000        6.59        0.850        1.000
1.000        1.00        3.00        3.000        2.000        6.59        0.850        1.000
1.000        1.00        3.00        4.000        4.000        6.90        1.000        1.000
1.000        1.00        3.00        4.000        2.000        2.84        0.820        1.000
1.000        1.00        3.00        4.000        1.000        14.51      1.000        1.000
1.000        1.00        3.00        4.000        1.000        14.51       1.000        1.000
1.000        1.00        3.00        4.000        1.000        10.42       1.000        1.000
1.000        1.00        3.00        4.000        3.000        24.63        0.890        2.000
1.000        1.00        3.00        4.000        3.000        107.31      0.890        2.000
1.000        2.00        1.00        3.000        2.000        48.66        0.830        1.000
1.000        2.00        1.00        3.000        1.000        32.34        0.930        1.000
1.000        2.00        1.00        4.000        4.000        3.39          0.830        2.000
1.000        2.00        1.00        4.000        4.000        3.39          0.830        2.000
1.000        2.00        2.00        4.000        2.000        39.57        0.840        1.000
1.000        2.00        2.00        4.000        2.000        39.57        0.840        1.000
1.000        2.00        2.00        2.000        2.000        26.40        0.820        2.000
1.000        2.00        3.00        4.000        1.000        31.23        0.350        2.000
1.000        2.00        3.00        4.000        2.000        10.10        0.830        3.000
1.000        2.00        3.00        4.000        2.000        10.10        0.830        3.000
1.000        4.00        1.00        4.000        1.000        117.25      0.800        1.000
0.000        1.00        2.00        1.000        3.000        27.78        0.570        2.000
0.000        1.00        2.00        1.000        3.000        27.78        0.570        2.000
0.000        1.00        2.00        1.000        1.000        0.85          0.940        1.000
0.000        1.00        2.00        1.000        1.000        0.85         0.940        1.000
0.000        2.00        1.00        4.000        2.000        83.70        0.690        3.000
0.000        2.00        3.00        4.000        3.000        217.75      1.000        1.000
0.000        3.00        2.00        3.000        3.000        50.30        0.840        3.000
0.000        3.00        2.00        2.000        2.000        313.26       0.640        1.000
0.000        3.00        3.00        1.000        4.000        231.15       0.830        1.000
0.000        3.00        3.00        1.000        4.000        64.00         0.830        1.000
0.000        3.00        3.00        4.000        3.000        227.80       0.620        1.000
0.000        3.00        3.00        4.000        3.000        57.94         0.620        1.000
0.000        3.00        3.00        4.000        3.000        321.60       0.880        2.000
0.000        4.00        1.00        2.000        3.000        854.33        0.710        2.000
0.000        4.00        1.00        2.000        3.000        388.81        0.590        3.000
0.000        4.00        1.00        2.000        3.000        388.81        0.590        3.000
0.000        4.00        2.00        4.000        4.000        53.46         0.880        3.000
0.000        4.00        3.00        2.000        2.000        277.50        0.570        3.000
0.000        4.00        3.00        2.000        2.000        277.50        0.570        3.000
0.000        4.00        3.00        1.000        3.000        321.92        0.620        1.000
0.000        4.00        3.00        1.000        3.000        321.92        0.620        1.000
;
run;

proc sort data=a;by y x1 x2 x3 x4 x5 x6 x7;run;

data b;
set a;
retain z1-z8;
if _n_=1 then do; num=1;z1=y;z2=x1;z3=x2;z4=x3;z5=x4;z6=x5;z7=x6;z8=x7;end;
else if z1=y and z2=x1 and z3=x2 and z4=x3 and z5=x4 and z6=x5 and z7=x6 and z8=x7 then num+1;
else do;num=1;z1=y;z2=x1;z3=x2;z4=x3;z5=x4;z6=x5;z7=x6;z8=x7;end;
output;
run;

data c d;
set b;
if num=1 then do;drop num;output c;end;
else do;drop num;output d;end;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-6-7 03:25:48
谢谢yongyitian及andre—sky!!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-6-7 03:28:56
请问yongyitian,“if first.x7 then output original;”这个语句什么意思,特别是“ if first.x7   ”是什么意思?谢谢!!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-6-7 04:09:52
lnlhckao123 发表于 2013-6-7 03:28
请问yongyitian,“if first.x7 then output original;”这个语句什么意思,特别是“ if first.x7   ”是什 ...
If you use a by statement along with a set statement in a data step then SAS creates two automatic variables, FIRST.variable and LAST.variable, where variable is the name of the by variable.  FIRST.variable has a value 1 for the first observation in the by group and 0 for all other observations in the by group. LAST.variable has a value 1 for the last observation in the by group and 0 for all other observations in the by group.

在数据步中, 使用 by 语句时,SAS建立两个自动变量,FIRST.variable的和LAST.variable,其中的变量是由变量的名称。 在一组相同的观测值中, 第一个观测值对应的 First.variable=1. 其他个观测值的对应的 FIRST.variable=0.

在一组相同的观测值中, 最后一次观测值对应的 Last.variable=1, 所有其他观测值对应的 last.variable=0.

当 first.variable^=1 时. 即为重复值

数据集按所有变量排续后, 当最后一个变量(x7)的first.variabl=1 时, 表示有重复观测的第一行




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群