BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
zhou_larry
Calcite | Level 5

Hey there, i'm trying to Left Join a variable but the column I'm matching it to are different data types. WHat is the best way to format it?

I tried to format ATSo.odr_number using $13.  but i keep getting errors. Should I use a Proc Format before this?

PROC SQL;

CREATE TABLE work.add_class AS

  SELECT ac.date_shipped, ac.order_id, ac.brand_code, ac.customer_id,

  ATSo.classification, ATSo.brand_code AS ATSbrand

  FROM work.add_cust AS ac

  LEFT JOIN work.TEMP_ORDERS AS ATSo

  ON ac.invoice_number = ATSo.odr_number $13.;

;

RUN

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

Use proc contents to check variable types. if ac.invoice_number is char then try this.

ON input(ac.invoice_number,8.) = ATSo.odr_number ;

View solution in original post

2 REPLIES 2
stat_sas
Ammonite | Level 13

Use proc contents to check variable types. if ac.invoice_number is char then try this.

ON input(ac.invoice_number,8.) = ATSo.odr_number ;

Hima
Obsidian | Level 7

proc sql;

create table work.add_class as

  select ac.date_shipped, ac.order_id, ac.brand_code, ac.customer_id,atso.classification, atso.brand_code as atsbrand

   from work.add_cust as ac left join work.temp_orders as atso

    on ac.invoice_number = put(atso.odr_number,char13.);

quit;

Example:

data have1;
input id $ var $;
cards;
1 a
2 b
3 c
;
run;

data have2;
input id var $;
cards;
1 a
2 b
3 c
;
run;

proc sql;
create table want as
select a.* from have1 a left join have2 b on a.id=put(b.id,char1.);
quit;

proc contents data=want;
run;

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

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 2 replies
  • 1683 views
  • 1 like
  • 3 in conversation