楼主: yz7891
7134 46

[原创博文] 数据比较问题 [推广有奖]

31
pinggutu 发表于 2010-4-28 01:53:08
crackman 发表于 2010-4-27 14:32
data a;
input x y z j@;
cards;
1 2 3 5
2 3 4 5
1 2 3 4
8 7 6 5
2 3 4 5
1 2 3 4
9 8 6 5
4 5 6 7
7 8 6 5
2 3 9 8
9 8 6 5
1 0 9 6
8 7 6 5
;
run;
proc sort data=a out=a;
by x y z j;
run;
data b;
set a;
x1=dif(x);
y1=dif(y);
z1=dif(z);
j1=dif(j);
if (x1=y1=z1=j1)=0 then output;
drop x1 y1 z1 j1;
retain n 0;
n=attrn(open('work.b','i'),'nobs');
run;
但是版主,我看运行出来的结果少了一行。你提供的数据有9行不同的数据,我只运行显示出8行不同的数据。
还有就是用select count(distinct *) 来做,编译出错!

32
jcjc0602 发表于 2010-4-28 02:50:29
路过~~~~~·

33
soporaeternus 发表于 2010-4-28 09:20:18
  1. data aa;
  2. if _N_=1 then do;
  3. declare hash h();
  4. h.definekey("x","y","z","j");
  5. h.definedata("x","y","z","j");
  6. h.definedone();
  7. end;
  8. set a;
  9. rc=h.find();
  10. if rc ^=0 then do;
  11.         h.add();
  12.         output;
  13. end;
  14. run;
复制代码
热闹热闹,看看对不对
Let them be hard, but never unjust

34
rosen123 发表于 2010-4-28 10:26:51
好东西啊,谢谢

35
liudeng2005 发表于 2010-4-28 10:45:43
不明白,感觉第一个问题,直接用proc sort 加option nodup就可以搞定
第二个问题,先用symput 计算出最大值
然后在data步中,引用宏变量就可以搞定。
已有 1 人评分热心指数 收起 理由
crackman + 1 好的意见建议

总评分: 热心指数 + 1   查看全部评分

36
crackman 发表于 2010-4-28 10:55:57
31# pinggutu
少了一个0
if (x1=y1=z1=j1=0)=0 then output;
n=attrn(open('work.b','i'),'nobs');
run;

37
crackman 发表于 2010-4-28 10:59:10
33# soporaeternus
127  data a;
128  input x y z j@;
129  cards;
NOTE: 数据集 WORK.A 有 13 个观测和 4 个变量。
NOTE: “DATA 语句”所用时间(总处理时间):
      实际时间          0.00 秒
      CPU 时间          0.00 秒

143  ;
144  run;
145  proc sort data=a out=a;
146  by x y z j;
147  run;
NOTE: 有 13 个从数据集 WORK.A 读取的观测。
NOTE: 数据集 WORK.A 有 13 个观测和 4 个变量。
NOTE: “PROCEDURE SORT”所用时间(总处理时间):
      实际时间          0.00 秒
      CPU 时间          0.00 秒

148  data b;
149  set a;
150  retain n 0;
151  x1=dif(x);
152  y1=dif(y);
153  z1=dif(z);
154  j1=dif(j);
155  if (x1=y1=z1=j1=0)=0 then output;
156  n=attrn(open('work.b','i'),'nobs');
157  run;
NOTE: 有 13 个从数据集 WORK.A 读取的观测。
NOTE: 数据集 WORK.B 有 9 个观测和 9 个变量。
NOTE: “DATA 语句”所用时间(总处理时间):
      实际时间          0.01 秒
      CPU 时间          0.01 秒




158  data aa;
159
160  if _N_=1 then do;
161
162  declare hash h();
163
164  h.definekey("x","y","z","j");
165
166  h.definedata("x","y","z","j");
167
168  h.definedone();
169
170  end;
171
172  set a;
173
174  rc=h.find();
175
176  if rc ^=0 then do;
177
178          h.add();
179
180          output;
181
182  end;
183
184  run;
NOTE: 有 13 个从数据集 WORK.A 读取的观测。
NOTE: 数据集 WORK.AA 有 9 个观测和 5 个变量。
NOTE: “DATA 语句”所用时间(总处理时间):
      实际时间          0.29 秒
      CPU 时间          0.03 秒

38
四弦黑白键 发表于 2010-4-28 11:24:58
帮你顶上去

39
soporaeternus 发表于 2010-4-28 11:31:28
37# crackman
我看到运行时间的差别了。
在9.1.3中貌似没有item_size函数来获得hash对象的个数,所以我让其遍历了一次全表,性能肯定低很多
Let them be hard, but never unjust

40
xqlove0520 发表于 2010-4-28 12:23:14
路过    顶下
选择决定你的人生未来,努力决定你能走多远,行动才能决定是否能得到,今天你行动?

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-1 14:11