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;
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.
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.