AdamO
AdamO

Reputation: 4930

concatenating an array in SAS using do loop

I have a SAS dataset like this:

 var1  var2 var3  var4  var5
there    is   no spoon   Neo

And want this:

var
thereisnospoonNeo

I have a data step like the following:

data want;
  set have;
  format var $100.;
  array v $ 5 var1-var5;
  var = "";
  do i=1 to 5;
    var = var || v{i};
  end;
run;

But my have has var = "";

Upvotes: 0

Views: 174

Answers (1)

AdamO
AdamO

Reputation: 4930

The issue is that the initial value of var is actually 100 characters of white space, and any concatenation truncates off the list. One must add

 var = strip(var) || v{i};

to achieve the desired result.

Upvotes: 0

Related Questions