I am getting the above error when i am trying to run this code below:
proc sql;
create table comp2
(keep=gvkey fyearq fqtr conm datadate rdq epsfxq epspxq
prccq ajexq spiq cshoq prccq ajexq spiq cshoq mcap /*Compustat variables*/
cshprq cshfdq rdq saleq atq fyr datafqtr
permno ticker )
as select *, (a.cshoq*a.prccq) as mcap
from mergetable
(where=((not missing(saleq) or atq>0) and consol='C' and
popsrc='D' and indfmt='INDL' and datafmt='STD' and not missing(datafqtr))) a
inner join
(select distinct gvkey, lpermno as permno, tic, min(linkdt) as mindate,
max(linkenddt) as maxdate from gvkeytable group by gvkey, tic) b
on a.gvkey=b.gvkey and b.mindate<=a.datadate<=b.maxdate;
quit;
Probably this:
b.mindate<=a.datadate<=b.maxdate
Some of these three variables are numeric and some are character, and this is not allowed and so SAS cannot do the desired comparison of dates. All three need to be all numeric. You need to check PROC CONTENTS from both datasets (mergetable and gvkeytable) to find out what the mismatch is, and then convert the variable to all numeric.
@PaigeMiller's comment about making all of the variables numeric is important. A character value like "2Apr" comes before "31Jan" because the rules for comparing character values do a character by character comparison from left to right. Since the '2' comes before '3' then the comparison would place the April date before January.
Even worse is when the "date" values are in a form like "April 15, 2020" because April would come before every other month.
Maxim 3: Know Your Data.
Run proc contents on your datasets and check the types of the variables used in the comparison. Since these look like dates, they should all be numeric and have a date format attached to them. If you find one where this is not true, fix the process that created it.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.