BookmarkSubscribeRSS Feed
rashmirao99
Fluorite | Level 6

Hi

I need to concatenate two variables.

Example:        treatment                                      Dose

                      adma;j;j;jkfddddddddddddd          30(ml)

 

Both are characters. I tried to concatenate them using " || ".  But Im getting like this  :  adma;j;j;jkfddddddddddddd  

                                                                                                                                            30(ml)

 Instead of getting it in one line :   adma;j;j;jkfddddddddddddd   30(ml).

 

Don't know why. Can someone please help with this?

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Is there a special chaaracter in either of those strings?  (Can happen when importing from Excel for instance).  Posting test data in the form of a datastep would go a long way to explaining it.  Follow this post on how to provide test data:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

Currently there is not much to suggest apart from compressing out special characters:

dose=compress(dose, "0a"x);

Is one, but there are others.

rashmirao99
Fluorite | Level 6
No. There is no special character.
RW9
Diamond | Level 26 RW9
Diamond | Level 26

And how do you know.  More importantly, how do we know.  We cannot see your system, or your data, or in fact what you are doing, or what you are getting out.  None of this information has been provided, hence we cannot help.  Provide test data in the form of a datastep.  Show what you are doing, then show log and output.

ballardw
Super User

When you use the || operator unless you specifically trim or strip a variable then the variable is padded to its assigned length.

Please look at the results of this example:

data example;
   length x $ 25 long y z $ 50;
   x= 'short';
   long= x||' word';
   y = strip(x)||' word'  ;
   z = catt(x,' word');
run;

the CATT function (and related CATS) may be better choices than the || operator.

 

With out showing how you are getting that result it may be that the split line behavior is attempting to show 50 or 60 characters in a table or view that is only 20 or so wide and so the result is wrapping.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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