SAS hash 树与多维临时数组的比较
2015-09-18 15:47
141 查看
代码来自SAS 官网
data bteam;
infile datalines;
input lname : $10. gender $ height weight
type;
datalines;
Adams M 67 160 2
Alexander M 69 115 1
Apple M 69 139 1
Arthur M 66 125 2
Avery M 66 152 2
Barefoot M 68 158 2
Baucom M 70 170 3
Blair M 69 133 1
Blalock M 68 148 2
Bostic M 74 170 3
;;;
proc print data=bteam;
title "BTEAM";
run;
data ideal;
infile datalines;
input height small medium large;
datalines;
66 126 138 149
67 130 141 154
68 134 145 158
69 138 149 162
70 142 153 167
71 146 157 172
72 150 161 177
73 154 165 181
74 158 169 185
75 162 173 189
;;;
proc print data=ideal;
title "IDEAL";
run;
data inshape outofshape;
keep lname height weight type;
array wt(66:75,3) _temporary_;
if _n_=1 then do;
do i=1 to
all;
set ideal nobs=all;
wt(height,1)=small;
wt(height,2)=medium;
wt(height,3)=large;
end;
end;
set bteam;
if gender='M' and (1 le type le 3) and (66 le
height le 75) then do;
if
wt(height,type)-5 le weight le wt(height,type)+5 then output
inshape;
else output
outofshape;
end;
else putlog 'WARNING: Observation out of lookup
range: ' _all_;
run;
proc print data=inshape;
title "Example 4.2 INSHAPE Data Set Created with
DATA Step";
run;
proc print data=outofshape;
title "Example 4.2 OUTOFSHAPE Data Set Created
with DATA Step";
run;
/***************************************************************************data
inshape outofshape;
attrib lname length=$10
gender length=$1
height length=8
weight length=8;
keep lname gender height weight;
if _n_=1 then do;
declare hash
wt(dataset:'ideal');
wt.defineKey('height');
wt.defineData('small','medium','large');
wt.defineDone();
call
missing(small,medium,large);
end;
set bteam;
if 66 le height le 75 and gender='M' and type
in (1,2,3) then do;
rc=wt.find();
if rc=0 then
do;
if type=1 then ideal=small;
else if type=2 then ideal=medium;
else if type=3 then ideal=large;
if ideal-5 le weight le ideal+5 then output inshape;
else output outofshape;
end;
else putlog
'WARNING: Height not found in hash object: ' _all_;
end;
else putlog 'WARNING: Observation out of range:
' _all_;
run;
proc print data=inshape;
title "Example 4.2 Related Technique INSHAPE
Data Set Created with DATA Step";
run;
proc print data=outofshape;
title "Example 4.2 Related Technique OUTOFSHAPE
Data Set Created with DATA Step";
run;
最后实现的结果都是
data bteam;
infile datalines;
input lname : $10. gender $ height weight
type;
datalines;
Adams M 67 160 2
Alexander M 69 115 1
Apple M 69 139 1
Arthur M 66 125 2
Avery M 66 152 2
Barefoot M 68 158 2
Baucom M 70 170 3
Blair M 69 133 1
Blalock M 68 148 2
Bostic M 74 170 3
;;;
proc print data=bteam;
title "BTEAM";
run;
data ideal;
infile datalines;
input height small medium large;
datalines;
66 126 138 149
67 130 141 154
68 134 145 158
69 138 149 162
70 142 153 167
71 146 157 172
72 150 161 177
73 154 165 181
74 158 169 185
75 162 173 189
;;;
proc print data=ideal;
title "IDEAL";
run;
data inshape outofshape;
keep lname height weight type;
array wt(66:75,3) _temporary_;
if _n_=1 then do;
do i=1 to
all;
set ideal nobs=all;
wt(height,1)=small;
wt(height,2)=medium;
wt(height,3)=large;
end;
end;
set bteam;
if gender='M' and (1 le type le 3) and (66 le
height le 75) then do;
if
wt(height,type)-5 le weight le wt(height,type)+5 then output
inshape;
else output
outofshape;
end;
else putlog 'WARNING: Observation out of lookup
range: ' _all_;
run;
proc print data=inshape;
title "Example 4.2 INSHAPE Data Set Created with
DATA Step";
run;
proc print data=outofshape;
title "Example 4.2 OUTOFSHAPE Data Set Created
with DATA Step";
run;
/***************************************************************************data
inshape outofshape;
attrib lname length=$10
gender length=$1
height length=8
weight length=8;
keep lname gender height weight;
if _n_=1 then do;
declare hash
wt(dataset:'ideal');
wt.defineKey('height');
wt.defineData('small','medium','large');
wt.defineDone();
call
missing(small,medium,large);
end;
set bteam;
if 66 le height le 75 and gender='M' and type
in (1,2,3) then do;
rc=wt.find();
if rc=0 then
do;
if type=1 then ideal=small;
else if type=2 then ideal=medium;
else if type=3 then ideal=large;
if ideal-5 le weight le ideal+5 then output inshape;
else output outofshape;
end;
else putlog
'WARNING: Height not found in hash object: ' _all_;
end;
else putlog 'WARNING: Observation out of range:
' _all_;
run;
proc print data=inshape;
title "Example 4.2 Related Technique INSHAPE
Data Set Created with DATA Step";
run;
proc print data=outofshape;
title "Example 4.2 Related Technique OUTOFSHAPE
Data Set Created with DATA Step";
run;
最后实现的结果都是
相关文章推荐
- 获取输入字符串的下一个字典序排列
- MySQL Join算法与调优白皮书(三)
- oracle回顾--视图、PL/SQL、游标
- Hello JSP!——内置对象基础练习题
- C#单链表的实现
- 误操作寄存器位引发的hardfault
- ctype.h 头文件
- NSMutableArray 初始化与添加删除程序
- 双set表整合出复杂的表(附有sas&n…
- 【转载】SAS Hash 对象
- 【转载】word 查找与替换中的…
- SAS--Perl Regular Expressi…
- sql合并复杂的表
- 【转载】COMPRESS 函数【功能…
- 【转载】SAS INTNX详解
- 用R软件绘制中国分省市地图
- SYSFUNC
- 【转载】format 与宏
- 口译常用成语
- 【转载】Windows下编写R pack…