BookmarkSubscribeRSS Feed
buechler66
Barite | Level 11

Hi. I have the following line of code. My goal is to set Rule = 'X' when Rule is missing.

 

    rule = tranwrd(rule,"SYSDATE",'X');

However I'm getting the following error (I think) because the value X isn't resolving as 'X'.  Does anyone have thoughts on resolving this issue?

 

9    + proc sql;
9    +                   create table QueryData as         (       select 'ACTUAL DELIVERY DATE MISMATCH' as RULE_NM,
       b.actual_dlvry_date as AD_DT,                 b.imb_code,                 2 as rule_order                 from
10   + iv_ora.bi_spm_piece_recon a,  bids_ora.bi_spm_piece_recon b                 where a.imb_code = b.imb_code
  and COALESCE(A.ACTUAL_DLVRY_DATE,X) <> COALESCE(B.ACTUAL_DLVRY_DATE,X)         );
ERROR: The COALESCE function requires its arguments to be of the same data type.
ERROR: The COALESCE function requires its arguments to be of the same data type.
ERROR: The following columns were not found in the contributing tables: X.

 

8 REPLIES 8
Reeza
Super User

I can't see the relation to the log and the code you've posted. 

 

The = sytnax is used in a data step not proc sql...

buechler66
Barite | Level 11

Sorry, here's the code relating to the above log.

 

 

		proc sql;
		create table QueryData as 
		(       select b.actual_dlvry_date as AD_DT, 
				b.imb_code, 
				&rule_order as rule_order
	            from iv_ora.bi_spm_piece_recon a,  bids_ora.bi_spm_piece_recon b                                                                                                                                                                                                                                                                                                                                                                                                                                                   
	            where a.imb_code = b.imb_code
	            and &rule
		); 
		quit;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Lets start again.  You have this code:

proc sql;
		create table QueryData as 
		(       select b.actual_dlvry_date as AD_DT, 
				b.imb_code, 
				&rule_order as rule_order
	            from iv_ora.bi_spm_piece_recon a,  bids_ora.bi_spm_piece_recon b                                                                                                                                                                                                                                                                                                                                                                                                                                                   
	            where a.imb_code = b.imb_code
	            and &rule
		); 
		quit;

Now the macro variable &RULE is resolving to:

COALESCE(A.ACTUAL_DLVRY_DATE,X) <> COALESCE(B.ACTUAL_DLVRY_DATE,X)

 Now, what the error is telling you is that X is not a variable in any of the contributing tables.  I assume what you want to do is to take the character X if the variable is null, so you want &RULE to resolve to:

COALESCE(A.ACTUAL_DLVRY_DATE,"X") <> COALESCE(B.ACTUAL_DLVRY_DATE,"X")

So that is how you need to setup the &RULE macro variable.  As we can't see how this is set - or in fact see any reason why that bit of code is in a macro variable in the first place, its hard to say where your going wrong.  I would suggest that your logic is in the first place incorrect, if either of those variables are actually date variables then "X" will not be valid compare.

 

Post some test data - in the form of a datastep and what you want the output to look like. 

Quentin
Super User
The error message is saying that the variable X was not found in the contributing tables. Perhaps you meant to reference the variable RULE? It's hard to guess.
BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
buechler66
Barite | Level 11
I was talking about the error: ERROR: The COALESCE function requires its arguments to be of the same data type.
Quentin
Super User

I believe the cause is the code you generated refers to a variable named X which doesn't exist in the contributing tables.  Then SAS will likely assume X is numeric, and your variable actual_delivery_date is probably character.  I would start by reviewing the code that generates the where clause.  Do really intend to refer to a variable named X?  If so, check why this variables isn't being found.

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Reeza
Super User

It seems to be the same issue you asked yesterday...you have a date in one part, the second part X needs to be a date.  

I still don't know what your first line of Rule= has to do with the code, what are you expecting to happen with that line of code?

 

Two other things:

If you want to use coalesce with character variables use COALESCEC- but since this is a date variable that doesn't make sense either. 

<> resolves to either MAX or NE depending on the usage, the log will state which one. This isn't a native SAS operator so if it was me, I would use NE.

 

http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000780367.htm

FreelanceReinh
Jade | Level 19

Just a side note: The COALESCE function of PROC SQL is different from the data step functions COALESCE and COALESCEC in that it accepts both numeric and character arguments as long as all arguments are of the same type.

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
  • 8 replies
  • 1064 views
  • 7 likes
  • 5 in conversation