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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Doc_Duke
Rhodochrosite | Level 12

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.

View solution in original post

3 REPLIES 3
Doc_Duke
Rhodochrosite | Level 12

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

where strip(A.ID)=strip(put(B.ID,7.));

Assuming A is the char and B the numeric.

Tom
Super User Tom
Super User

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;

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!

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.

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
  • 3 replies
  • 800 views
  • 6 likes
  • 4 in conversation