Hi,
I am trying to join two datasets (using proc sql) on an ID variable. Though the values of the ID variables match to the other dataset, one of the ID variables is numeric and one is character. I tried converting the numeric one to character using ID_char=put(ID, 7.), and that worked, enabling me to join on some of the values of ID. The problem is that there are some other values of ID that are length 6, and those will not join to the other dataset, presumably because SAS added a trailing blank and that doesn't match to the version in the other set which has no blank (I'm guessing).
Any help is much appreciated.
It may be more likely that the original character variable had a leading blank. You can tell by printing some of the offending IDs in Hex.
Another alternative would be to recode BOTH IDs to be left justified.
It may be more likely that the original character variable had a leading blank. You can tell by printing some of the offending IDs in Hex.
Another alternative would be to recode BOTH IDs to be left justified.
Hi,
where strip(A.ID)=strip(put(B.ID,7.));
Assuming A is the char and B the numeric.
I like CATS() as a function that doesn't care whether its inputs are character or numeric.
data A ;
id=7;
A=1;
run;
data B;
id=' 7 ';
B=1;
run;
proc sql ;
select * from A,B where cats(a.id)=cats(b.id) ;
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.