BookmarkSubscribeRSS Feed
shweta_234
Fluorite | Level 6

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;

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
ballardw
Super User

@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.

 

Kurt_Bremser
Super User

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 3 replies
  • 802 views
  • 0 likes
  • 4 in conversation