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-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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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