This script creates a temporary dataset to compare two methods of concatenating character strings containing superfluous spaces. It contrasts the classic method using a combination of TRIM, LEFT, and the concatenation operator (!!) with the modern CATX function, which automatically handles blank suppression and separator insertion.
Data Analysis
Type : CREATION_INTERNE
Data is dynamically created in the Data step (variables a and b initialized with literal strings).
1 Code Block
DATA STEP Data
Explanation : Data step creating the 'test' table. Variable 'c' shows complex manual concatenation (trimming leading/trailing spaces then joining). Variable 'd' shows the use of CATX(' ', a, b) which performs the same operation more concisely. Results are sent to the log via PUT.
Copied!
data test ;
a=' Phil ' ;
b=' Mason ' ;
c=trim(left(a))!!' '!!left(b) ;
d=catx(' ',a,b) ;
put c= d= ;
run ;
1
DATA test ;
2
a=' Phil ' ;
3
b=' Mason ' ;
4
c=trim(left(a))!!' '!!left(b) ;
5
d=catx(' ',a,b) ;
6
put c= d= ;
7
RUN ;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.