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

Hi,

 

I have 2 tables I need to join by a variable.  The thing is they have different types.  

 

 VariableTypeLenFormatInformat
Table AxxChar8$CHAR8.$CHAR8.
Table BxxNum819.19.

 

I need the join statement.  I tried below and returned no rows. Is my join correct?  Please only focus on the JOIN clause and not any other part of the code.

 

proc sql;

select *

from tableA a

inner join tableB b on input(a.xx, 8.) = b.xx;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@jffeudo86 

The join as posted should be o.k. so it's either something in the data or your actual join is different from what you show us.

When inspecting the keys in your source data can you identify at least one case where you'd expect a match?

data tableA;
  attrib xx format=$char8. informat=$char8.;
  do xx='1','2','3';
    xx=' '||xx;
    len_a_xx=lengthn(xx);
    output;
  end;
  stop;
run;

data tableB;
  attrib xx format=19. informat=19.;
  do xx=1,3,4;
    output;
  end;
  stop;
run;

proc sql;
  select 
    a.xx as a_xx, 
    len_a_xx,
    b.xx as b_xx
  from 
    tableA a inner join tableB b 
      on input(a.xx, 8.) = b.xx
  ;
run;

Capture.JPG

View solution in original post

3 REPLIES 3
ballardw
Super User

@jffeudo86 wrote:

Hi,

 

I have 2 tables I need to join by a variable.  The thing is they have different types.  

 

  Variable Type Len Format Informat
Table A xx Char 8 $CHAR8. $CHAR8.
Table B xx Num 8 19. 19.

 

I need the join statement.  I tried below and returned no rows. Is my join correct?  Please only focus on the JOIN clause and not any other part of the code.

 

proc sql;

select *

from tableA a

inner join tableB b on input(a.xx, 8.) = b.xx;

run;


One would suspect that if you have a default format of 19. for a numeric variable that perhaps in needs more than 8 digits to represented which means that your other variable may be missing enough characters to make matches.

 

I suggest a small experiment just creating values with your input as shown, ignore the other set, and see what values you get. Do they look like the ones in b?

 

You really should show us some example values that you expect to match.

 

Patrick
Opal | Level 21

@jffeudo86 

The join as posted should be o.k. so it's either something in the data or your actual join is different from what you show us.

When inspecting the keys in your source data can you identify at least one case where you'd expect a match?

data tableA;
  attrib xx format=$char8. informat=$char8.;
  do xx='1','2','3';
    xx=' '||xx;
    len_a_xx=lengthn(xx);
    output;
  end;
  stop;
run;

data tableB;
  attrib xx format=19. informat=19.;
  do xx=1,3,4;
    output;
  end;
  stop;
run;

proc sql;
  select 
    a.xx as a_xx, 
    len_a_xx,
    b.xx as b_xx
  from 
    tableA a inner join tableB b 
      on input(a.xx, 8.) = b.xx
  ;
run;

Capture.JPG

jffeudo86
Quartz | Level 8
Thank you! New to SAS so I just wanted to know that my join is correct, or if not, be given direction on how to do it.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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