@sastuck wrote:
Hello!
I am trying merge two datasets by ticker and year. When I run the code, however, SAS brings up an issue with another variable, cusip. I understand that the issue is that one dataset has this variable as a character variable while the other has it as a numeric one. That being said, shouldn't this be unrelated if I am trying to merge by ticker and year?
Yes it is critical a data set variable may only have one type. Since you have two different types SAS does not know which data type you actually want.
I would guess the "cusip" is something like "customer ip" or similar. If the value is an identifier and is not going to have arithmetic performed with it then likely it should be character.
You can over come issues like this by: 1) Best is controlling you data at import/creation (in this case note that you used guessing rows in on proc import and not the other which is a likely cause in this case) such as actually reading data when practical using a documented description of the data file(s) in question.
2) lots of "fixit" code like; Assumes the firms_sorted is the set with the numeric version of the cuspid and a character version is desired.
DATA ceo_firm;
MERGE ceos_sorted
firms_sorted (rename=(cuspid=cuspnum) )
;
BY ticker year;
/* to keep the version from the firms_sorted set the way MERGE would work the 12 in the next line should match the lenght of the
character version of cuspid
*/
if not missing(cuspnum) then cuspid = put(cuspnum,best12. -L);
drop cuspnum;
RUN;
Or if you don't need the cuspid for any further analysis:
DATA ceo_firm;
MERGE ceos_sorted (drop=cuspid )
firms_sorted (drop=cuspid )
;
BY ticker year;
RUN;
... View more