SAS Code Fragments
Concatenating string variables using CAT functions

data test;
   infile cards missover;
   length first last $20;
   input first $ last $  ;
datalines;
jone smith
john wayne
bill 
phil hodge
;
run;
data test2;
  set test;
  name = catx(", ", of last first );
  name1 = cat(of last first);
  name2 = cats(of last first); /*leading and trailing blanks*/
  name3 = catt(of last first); /*trailing blanks*/
run;
proc print data = test2;
run;

   Obs    first    last     name                    name1              name2        name3

    1     jone     smith    smith, jone    smith               jone    smithjone    smithjone
    2     john     wayne    wayne, john    wayne               john    waynejohn    waynejohn
    3     bill              bill                               bill    bill         bill
    4     phil     hodge    hodge, phil    hodge               phil    hodgephil    hodgephil
 

For more details on these functions, see SAS online documentation of CAT function.

How to cite this page

Report an error on this page or leave a comment

The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.