BookmarkSubscribeRSS Feed
Pabster
Obsidian | Level 7

UPDATE:

Now this is my log:

3848  data want (drop=_:);
3849    if _n_=1 then do;
3850      /*Make Lookup Table of active companies, with AT as lookup key */
3851      if 0 then
3852        set Altman.size (keep=COSTAT AT GVKEY rename=(AT=matched_at GVKEY=matched_gvkey));
3853      declare hash
3854        actives(ordered:'A'
3855               ,dataset:'Altman.size(where=(COSTAT="1" and not missing("AT"))
3856                              keep=COSTAT AT GVKEY
3857                              rename=(AT=matched_at GVKEY=matched_gvkey))');
3858        actives.definekey('matched_at');
3859        actives.definedata('matched_at','matched_gvkey');
3860        actives.definedone();
3861      declare hiter hi ('actives');
3862    end;
3863
3864    /*Read inactive companies, one at a time*/
3865    set Altman.size (where=(COSTAT='1'));
3866
3867    /*Use inactive AT as a lookup key */
3868    _rc=actives.find(key:AT);
3869
3870    /*If not found, then check higher and lower neighbors to find nearest*/
3871    if _rc^=0 then do;
3872      /* Insert inactive AT into the ordered hash of active ATs*/
3873      actives.add(key:AT,data:.,data:.);
3874
3875      /* Point iterator at the inserted value */
3876      hi.setcur(key:AT);
3877
3878      /* Iterate to next higher neighbor and save values */
3879      _rc=hi.next();
3880      _at_next=matched_at;
3881      _gvkey_next=matched_gvkey;
3882
3883      /* Re-point iterator and iterate down one neighbor */
3884      hi.setcur(key:AT);
3885      _rc=hi.prev();
3886
3887      /* Choose closest of the two */
3888      if (_at_next-at) < (at-matched_at) then do;
3889        matched_at=_at_next;
3890        matched_gvkey=_gvkey_next;
3891      end;
3892
3893      _rc=hi.prev();
3894      _rc=actives.remove(key:at);
3895    end;
3896    _rc=actives.remove(key:matched_at);
3897  run;

NOTE: There were 1279 observations read from the data set ALTMAN.SIZE.
      WHERE COSTAT='1';
ERROR: Type mismatch for data variable matched_gvkey at line 3873 column 5.
ERROR: Keys and data must be specified in the same order and have the same types as given in
       DefineKey/DefineData at line 3873 column 5.
ERROR: DATA STEP Component Object failure.  Aborted during the EXECUTION phase.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 427 observations read from the data set ALTMAN.SIZE.
      WHERE COSTAT='1';
WARNING: The data set WORK.WANT may be incomplete.  When this step was stopped there were 426
         observations and 21 variables.
WARNING: Data set WORK.WANT was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.10 seconds
      cpu time            0.09 seconds

mkeintz
PROC Star

This is one of the problems of not having a sample data set - I can't test my program.

 

I believe, in my cleverness at renaming AT  to AT_MATCHED, I overlooked the need to corresponding change the "not missing" condition from

    and not missing(AT)

to

    and not missing(AT_matched)

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Pabster
Obsidian | Level 7

@mkeintz here is a link to download my data table that I use:

https://wetransfer.com/downloads/84f12e63bcdc34dd7efb6ef7c5559d7620190226191457/b8e8357e2f62c9c77060...

Also , just in case the code result ends up similar to the one offered by @PaigeMiller , the format I am trying to end with is the same as the first I uploaded (which the data table I sent on the link also)
Screen Shot 2019-02-26 at 2.18.40 PM.png 
The only thing I want to modify on it is to be able to see one company line (everything kept the same as it is) that is Inactive with the Paired Active company to it.
So the Costat appears:
0
1
0
1


SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 17 replies
  • 3064 views
  • 2 likes
  • 4 in conversation