BookmarkSubscribeRSS Feed
scify
Obsidian | Level 7

I have the following piece of code that works fine as a standalone pull:

 

proc sql;
	connect to teradata (authdomain='LDAP_auth' SERVER= teramed1 mode = teradata);
	create table test as 
	select * from connection to teradata (
select sub_ed.eci, sub_ed.hh_episode_bgn,count(sub_ed.incurred_dt) as ed_during_ct
, min(incurred_dt) as ed_during_dt from sudd02a.hh_3_ed sub_ed left join sudd02a.hh_1_episodes sub_ep on sub_ed.eci = sub_ep.eci and sub_ed.hh_episode_bgn = sub_ep.hh_episode_bgn group by 1,2 where sub_ed.incurred_dt between sub_ed.hh_episode_bgn and sub_ep.hh_episode_end); quit;

However, when I wrap the select statement into a left join as part of a much larger pull from Teradata

 

 

left join (select sub_ed.eci, sub_ed.hh_episode_bgn
		, count(sub_ed.incurred_dt) as ed_during_ct
		, min(incurred_dt) as ed_during_dt
		from sudd02a.hh_3_ed sub_ed left join sudd02a.hh_1_episodes sub_ep
		on sub_ed.eci = sub_ep.eci and sub_ed.hh_episode_bgn = sub_ep.hh_episode_bgn
		group by 1,2
		where sub_ed.incurred_dt between sub_ed.hh_episode_bgn and sub_ep.hh_episode_end) ed2
on ep.eci=ed2.eci and ep.hh_episode_bgn=ed2.hh_episode_bgn

Enterprise Guide throws the error:

 

ERROR: Teradata prepare: Datatype Mismatch in THEN/ELSE expression.

 

I can't figure out what might be causing that error. It's not the ON variables: there's a join just above this one that uses the exact same tables and variables, and it works fine. 

 

1 REPLY 1
ChrisNZ
Tourmaline | Level 20

It looks like your ed2 variables have a different type.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1880 views
  • 0 likes
  • 2 in conversation