BookmarkSubscribeRSS Feed
hnb_matt_d
Obsidian | Level 7
Hey, everyone... I'm trying to convert a numerical variable to a character variable to be able to join an additional table (each one has the same variable nomenclature, but one is numerical and one is character... (not my) poor design, I know. The variable customer_id is numerical in the xxx_customers table with a length of 8 bytes and format/informat of 20. Same variable (customer_id) is character in the xxx_investigation_relationship table with a length of 50 bytes and format/informat of $50. I'm wanting to change the numerical variable in the xxx_customers table to character for joining the xxx_investigation_relationship table. The customer_id can vary from as few as four (4) digits to as many as eight (8) digits. Not sure if that matters when converting to character. I tried using put(xxx_customers.customer_id, 8.) as customer_id. While it did change the format to character, the join won't produce results (which it should as I've manually checked some customer_id to find them in each table). Thanks in advance for any and all assistance rendered.
2 REPLIES 2
ballardw
Super User

When you use PUT to create a character variable from numeric the results by default are right justified so you end up with leading spaces for values less than 8, in your example, digits.

Use the -L justification option:  put(var, 8 -L) to create a left justified variable.

PaigeMiller
Diamond | Level 26

While it did change the format to character, the join won't produce results

 

There could be a lot of reasons for this.

 

Show us examples of typical values in each of the two variables. Let's say we need to see a dozen example. Show us the code you used.

--
Paige Miller

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
  • 2 replies
  • 678 views
  • 0 likes
  • 3 in conversation