Desktop productivity for business analysts and programmers

Change a Columns datatype to allow a Join

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 80
Accepted Solution

Change a Columns datatype to allow a Join

Hi Forum,

I'm using SAS Enterprise Guide 4.3 with Windows 7 in case it's useful.

I have 2 tables, with a Month_Id written as '201310' to denote October 2013 for example.

Problem is, I have one table with this Column created as an Integer & another as a Varchar.

What is the best way to change one of them to the others datatype so I can join them?

Thanks


Accepted Solutions
Solution
‎11-10-2013 06:41 PM
Respected Advisor
Posts: 3,836

Re: Change a Columns datatype to allow a Join

The EG Query Builder is a wizard which generates SQL code. As with all wizards there are always limitations.

What proposes would work but I haven't found a way using the wizard to generate such code.

If you need an inner join (so the result only containing matching rows) then you could "trick" the wizard by not defining a join at all but by defining a filter (this results in an implicit inner join).

I'm using an expression 'input(character_key, best16.)' which converts the digits in the character variable into a numeric value before comparing with the numeric key.

Capture.PNG

If you need another sort of join (eg. a left join) then I believe you need first a query builder node to create a calculated field which contains this numeric value (so you're using the input() there) and then you use the output table of this query in the next query builder where you join the 2 tables together.

View solution in original post


All Replies
Grand Advisor
Posts: 10,211

Re: Change a Columns datatype to allow a Join

Join on put(integervaluedvariable, f6.) = characterversion

Frequent Contributor
Posts: 80

Re: Change a Columns datatype to allow a Join

Hi ballardw,

Thanks for the response but I don't know what you mean?

Could you explain it in terms of using a Query builder with 2 tables, one table 'Table1' with the field 'Mon_Yr' as an Integer datatype & another table 'Table2' with the field 'Mon_Yr' as a Varchar datatype?

Thanks

Solution
‎11-10-2013 06:41 PM
Respected Advisor
Posts: 3,836

Re: Change a Columns datatype to allow a Join

The EG Query Builder is a wizard which generates SQL code. As with all wizards there are always limitations.

What proposes would work but I haven't found a way using the wizard to generate such code.

If you need an inner join (so the result only containing matching rows) then you could "trick" the wizard by not defining a join at all but by defining a filter (this results in an implicit inner join).

I'm using an expression 'input(character_key, best16.)' which converts the digits in the character variable into a numeric value before comparing with the numeric key.

Capture.PNG

If you need another sort of join (eg. a left join) then I believe you need first a query builder node to create a calculated field which contains this numeric value (so you're using the input() there) and then you use the output table of this query in the next query builder where you join the 2 tables together.

Frequent Contributor
Posts: 80

Re: Change a Columns datatype to allow a Join

Thanks ballardw/Patrick,

I'll give these a try.  :smileycool:


☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 2227 views
  • 3 likes
  • 3 in conversation