DATA Step, Macro, Functions and more

concatenating two strings

Reply
Occasional Contributor
Posts: 12

concatenating two strings

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?

Super User
Super User
Posts: 9,853

Re: concatenating two strings

Posted in reply to rashmirao99

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.

Occasional Contributor
Posts: 12

Re: concatenating two strings

No. There is no special character.
Super User
Super User
Posts: 9,853

Re: concatenating two strings

Posted in reply to rashmirao99

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.

Super User
Posts: 13,941

Re: concatenating two strings

Posted in reply to rashmirao99

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.

Ask a Question
Discussion stats
  • 4 replies
  • 85 views
  • 0 likes
  • 3 in conversation