BookmarkSubscribeRSS Feed
zjanuske
Calcite | Level 5

Hi,

 

I'm running a proc sql table, trying to compare dates in the WHERE statement. I keep getting this error: "Expression using equals (=) has components that are of different data types.".

 

I have run proc contents to compare formats of both variables, and they look the same:

Capture1.PNGCapture2.PNG

 

The code I'm running:

PROC SQL;
CREATE TABLE TRACKER_REDEMPTIONS AS SELECT t.*, r.redemptions FROM tracker_work4 T LEFT JOIN new_redemptionst r ON 
((T.STORE=r.store) AND 
(T.CAMPAIGN = r.campaign) AND 
(T.start <= r.sunday) AND
(T.'Last Expiry Date'n >= r.sunday)) ;
RUN;

 

I'm out of ideas for what could be wrong. Help!

7 REPLIES 7
art297
Opal | Level 21

You didn't show the contents for ALL of the variables shown in your statement, specifically t.start.

 

You also might run into a problem, albeit a different one, in that the lengths of t.campaign and r.campaign are different.

 

Art, CEO, AnalystFinder.com

 

zjanuske
Calcite | Level 5

t.start specifications are exactly the same as Last Expiry Date (or r.sunday). I'm currently only trying to solve the dates issue, not worrying about campaign length yet. 

art297
Opal | Level 21

What about t.store and r.store?

 

Art, CEO, AnalystFinder.com

 

zjanuske
Calcite | Level 5

they;re both fine, the error is on those two lines i've highlighted in red

art297
Opal | Level 21

Post your log and the full proc contents of both datasets.

 

Art, CEO, AnalystFinder.com

 

Astounding
PROC Star

Things not shown, that need to be checked:

 

T.start ... is it character or numeric?

 

The global option VALIDVARNAME has to be set to ANY to permit name literals as field names.

Amir
PROC Star

Hi,

 

The error might not be in the lines you highlighted in red as they are using comparison operators <= and >= which for the following different data types causes a different error message:

 

proc sql noprint;
   create table tmp as
   select a.*
         ,b.weight
   from sashelp.class(drop = weight) a
   left join sashelp.class b
   on a.name >= b.age
   ;
quit;

 

gives the error:

 

14 proc sql noprint;

15 create table tmp as

16 select a.*

17 ,b.weight

18 from sashelp.class(drop = weight) a

19 left join sashelp.class b

20 on a.name >= b.age

21 ;

ERROR: Expression using greater than or equal (>=) has components that are of different data types.

NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.

22 quit;

NOTE: The SAS System stopped processing this step because of errors.

 

As you can see it refers to greater than or equal (>=) not just equals (=) which your message does.

 

Changing my code to use = instead of >= gives the same error message as yours, so this indicates that the issue is with your equality tests T.STORE=r.store or T.CAMPAIGN = r.campaign.

 

As others have advised, seeing all the relevant information would help us to help you.

 

Just another thought, are either of the data sets views?

 

 

Regards,

Amir.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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