1

I am working with catx function in sas enterprise guide. When I want to concatenate 2 columns I am using

catx('-',column1,column2)

It works fine but when both column1 and column2 are null it still gives '-' as output

How to restrict this, if both are null just give me null

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
sra
  • 167
  • 8
  • Do you also what it to add the hyphen when only one of the values is missing? – Tom Jul 26 '23 at 14:57
  • What do the values show when you format the columns with $HEX32. ? If it's not 2020202020... then you have control characters in your values. – Richard Jul 26 '23 at 17:59

2 Answers2

2

CATX will return a null (blank) value if all concatenation values are blank.

If your result is appearing as - then your values probably are an invisible non-printable character such as tab, newline or carriage return.

Look ma, no dash!


data have;
s=' ';
t=' ';
u = catx('-',s,t);
run;

proc sql;
  create table result as select s,t,catx('-',s,t) as u from have;
quit;

enter image description here

enter image description here

Richard
  • 25,390
  • 3
  • 25
  • 38
1

Try the following :

/* Using PROC SQL */
proc sql;
    SELECT 
        CASE 
            WHEN column1 IS NOT NULL OR column2 IS NOT NULL THEN catx('-', column1, column2)
            ELSE NULL
        END AS concatenated_columns
    FROM your_table;
quit;
Amira Bedhiafi
  • 8,088
  • 6
  • 24
  • 60