BookmarkSubscribeRSS Feed
Konkordanz
Pyrite | Level 9

hi,

 

Ive two column (Char,Code) and I just want to combine them (into result). But how? Could you pls help me with SAS- and SQL-command? Thank you!

 

Char Code Result
KA 14523 KA14523
3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20
Result = cats(Char, Code);
PaigeMiller
Diamond | Level 26

Yes, the simplest answer is given by @PeterClemmensen 

 

However, you might want to familiarize yourself with the entire family of CAT functions as they may be helpful in other situations

CAT

CATQ

CATS

CATT

CATX

DOGX (<- there is no such thing)

--
Paige Miller
ballardw
Super User

If your code variable is numeric you need to consider cases of differing number of digits and what you expect for the result. If you always want 5 digits in the combined value and the Code value is less than 10000 you may need to control the conversion to character as the default may not yield the desired need.

data example;
   char ='ABC';
   code = 3;
   combined= cats(char,code);
   combined2 = cats(char,put(code,z5.));
   put combined= combined2=;
run;

Yields:

combined=ABC3 combined2=ABC00003

The automatic conversion to character for the CAT (and most functions) will use a BEST format which may have fewer digits than you want/need/expect.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 3 replies
  • 737 views
  • 1 like
  • 4 in conversation