I am trying to link on a character field but 1 table the character is 3 digits and the other it is 4 digits. I was going to add a leading zero to the 3 digits but I can only see how to use the z function with numbers not characters. I think I need to use a right conc function but I can't figure out how to make that join.
I am using SAS not SQL
@ljw4 wrote:
I am using SAS not SQL
In SAS to use SQL syntax you need to use it inside of PROC SQL step.
Do you totally not want to use any SQL code?
If you really must use data step to join the tables then you will need modify one or both of the variables.
data for_merge_one;
set one;
numid = input(id,32.);
run;
proc sort; by numid; run;
data for_merge_two;
set two;
numid=input(id,32.);
run;
proc sort; by numid; run;
data want;
merge for_merge_one for_merge_two;
by numid;
run;
If you use SQL to join you can match on function results.
If the strings are just digit strings of less 16 characters then just convert both to numbers and match the numbers.
proc sql;
create table want as
select *
from table1
inner join table2
on input(table1.id,32.) = input(table2.id,32.)
;
quit;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.