Yeah I figured it out but now I am stock with this code: data want (drop=_:);
if _n_=1 then do;
/*Make Lookup Table of active companies, with AT as lookup key */
if 0 then
set Altman.size (keep=COSTAT AT GVKEY rename=(AT=matched_at GVKEY=matched_gvkey));
declare hash
actives(ordered:'A'
,dataset:'Altman.size(where=(COSTAT='1' and not missing(at))
keep=COSTAT AT GVKEY
rename=(AT=matched_at GVKEY=matched_gvkey))');
actives.definekey('matched_at');
actives.definedata('matched_at','matched_gvkey');
actives.definedone();
declare hiter hi ('actives');
end;
/*Read inactive companies, one at a time*/
set Altman.size (where=(COSTAT='1'));
/*Use inactive AT as a lookup key */
_rc=actives.find(key:AT);
/*If not found, then check higher and lower neighbors to find nearest*/
if _rc^=0 then do;
/* Insert inactive AT into the ordered hash of active ATs*/
actives.add(key:AT,data:.,data:.);
/* Point iterator at the inserted value */
hi.setcur(key:AT);
/* Iterate to next higher neighbor and save values */
_rc=hi.next();
_at_next=matched_at;
_gvkey_next=matched_gvkey;
/* Re-point iterator and iterate down one neighbor */
hi.setcur(key:AT);
_rc=hi.prev();
/* Choose closest of the two */
if (_at_next-at) < (at-matched_at) then do;
matched_at=_at_next;
matched_gvkey=_gvkey_next;
end;
_rc=hi.prev();
_rc=actives.remove(key:at);
end;
_rc=actives.remove(key:matched_at);
run; and this log : 3536 data want (drop=_:);
3537 if _n_=1 then do;
3538 /*Make Lookup Table of active companies, with AT as lookup key */
3539 if 0 then
3540 set Altman.size (keep=COSTAT AT GVKEY rename=(AT=matched_at GVKEY=matched_gvkey));
3541 declare hash
3542 actives(ordered:'A'
3543 ,dataset:'Altman.size(where=(COSTAT='1' and not missing(at))
-----------------------------
49 388
200
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS
release. Inserting white space between a quoted string and the succeeding
identifier is recommended.
ERROR 388-185: Expecting an arithmetic operator.
ERROR 200-322: The symbol is not recognized and will be ignored.
3544 keep=COSTAT AT GVKEY
3545 rename=(AT=matched_at GVKEY=matched_gvkey))');
3546 actives.definekey('matched_at');
ERROR: DATA STEP Component Object failure. Aborted during the COMPILATION phase.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.06 seconds
3547 actives.definedata('matched_at','matched_gvkey');
3548 actives.definedone();
3549 declare hiter hi ('actives');
3550 end;
3551
3552 /*Read inactive companies, one at a time*/
3553 set Altman.size (where=(COSTAT='1'));
3554
3555 /*Use inactive AT as a lookup key */
3556 _rc=actives.find(key:AT);
3557
3558 /*If not found, then check higher and lower neighbors to find nearest*/
3559 if _rc^=0 then do;
3560 /* Insert inactive AT into the ordered hash of active ATs*/
3561 actives.add(key:AT,data:.,data:.);
3562
3563 /* Point iterator at the inserted value */
3564 hi.setcur(key:AT);
3565
3566 /* Iterate to next higher neighbor and save values */
3567 _rc=hi.next();
3568 _at_next=matched_at;
3569 _gvkey_next=matched_gvkey;
3570
3571 /* Re-point iterator and iterate down one neighbor */
3572 hi.setcur(key:AT);
3573 _rc=hi.prev();
3574
3575 /* Choose closest of the two */
3576 if (_at_next-at) < (at-matched_at) then do;
3577 matched_at=_at_next;
3578 matched_gvkey=_gvkey_next;
3579 end;
3580
3581 _rc=hi.prev();
3582 _rc=actives.remove(key:at);
3583 end;
3584 _rc=actives.remove(key:matched_at);
3585 run;
... View more