SAS  hash 树与多维临时数组的比较

来源:互联网 发布:大庆油田网络客服电话 编辑:程序博客网 时间:2024/06/05 07:57

代码来自SAS 官网

 

data bteam;
  infile datalines;
  input lname : $10. gender $ height weighttype;
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 toall;
     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 leheight le 75) then do;
    ifwt(height,type)-5 le weight le wt(height,type)+5 then outputinshape;
    else outputoutofshape;
  end;
  else putlog 'WARNING: Observation out of lookuprange: ' _all_;
run;

proc print data=inshape;
  title "Example 4.2 INSHAPE Data Set Created withDATA Step";
run;
proc print data=outofshape;
  title "Example 4.2 OUTOFSHAPE Data Set Createdwith DATA Step";
run;


/***************************************************************************
datainshape 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 hashwt(dataset:'ideal');
   wt.defineKey('height');
   wt.defineData('small','medium','large');
   wt.defineDone();
    callmissing(small,medium,large);
  end;

  set bteam;

  if 66 le height le 75 and gender='M' and typein (1,2,3) then do;
   rc=wt.find();
    if rc=0 thendo;
     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 INSHAPEData Set Created with DATA Step";
run;
proc print data=outofshape;
  title "Example 4.2 Related Technique OUTOFSHAPEData Set Created with DATA Step";
run;

最后实现的结果都是

SAS <wbr> <wbr>hash <wbr>树与多维临时数组的比较

0 0
原创粉丝点击