2 Replies Latest reply: Apr 15, 2017 6:28 AM by Stefan Wühl RSS

    How to Concatenate Multiple String Variables within a Row in the Script

    Patrick F

      Greetings,

       

      I am trying to figure out how to concatenate multiple string variables within a row, in the script, and only show comma delimiters where the variable is populated (i.e. it is not null).  I know that you can use ampersands for concatenation, but that does not work without writing a lot of conditional code.  Also, I am not trying to collapse values across different rows (which is what the CONCAT function appears to be for).  I just want the concatenation to occur within each row/observation. Is there a function or some relatively simple code to handle this?  Below is a table that shows some fake data, and the desired output.

       

      Variable 1Variable 2Variable 3Variable 4Desired Variable
      AABBCCAA, BB, CC
      BBDDBB, DD
      CCCC
      AABBCCDDAA, BB, CC, DD
      AADDAA, DD
      BBBB

       

      Thank you for your time,

      Patrick