title: Concatenating 3 variable name in a new variable within a datastep by using an array reference
body: <p>I would like to create a variable called DATFL that would have the following values for the last obseration :</p>
  
  <pre><code>DATFL
  gender/scan
  </code></pre>
  
  <p>Here is the code :</p>
  
  <pre><code>data mix_ ;
  input id $  name $  gender $  scan $;
  datalines;
  1 jon   M  F
  2 jill  F  L
  3 james F  M
  4 jonas M  M
  ;
  run;
  
  data mix_3; set mix_; 
  length datfl datfl_ $ 50;
  array m4(*) id name gender scan;
  retain datfl;
   do i=1 to dim(m4);
    if index(m4(i) ,'M') then do; 
      datfl_=vname(m4(i)) ;
      if missing(datfl) then datfl=datfl_;
      else datfl=strip(datfl)||"/"||datfl_;
    end;
   end;
  
  run;
  </code></pre>
  
  <p>Unfortunately, the value I get for 'DATFL' at the last observation is 'gender/scan/gender/scan'.Obviously  because of the retain statement that I used for 'DATFL' I ended up with duplicates. At the end of this data step, I was planning to use a  CALL SYMPUT statement to load the last value into macro variable but I won't do it until I fix my issue...Can anyone provide me with a  guidance on how to prevent 'DATFL' to have duplicates value at the end of the dataset ? Cheers
  sas_kappel</p>