<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: merge columns in the same dataset without duplicates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876067#M346152</link>
    <description>&lt;P&gt;First thing I am concerned is that you show . in the example "data". That would typically mean in a SAS data set that the value of the variable is numeric and so INDEXW would not typically be appropriate.&lt;/P&gt;
&lt;P&gt;Second, you should show what you expect as a result when there are different values in at least some of the observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Third provide a data step with some example values. NOTE that the post you linked says "No data so untested".&lt;/P&gt;
&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;Data test2;
   set test;
   array values (*) email_1-email_5;
   length Email $ 125 ;
   do i=1 to dim(values);
      if indexw(strip(Email),strip(values[i]),'/')= 0 then Email= catx('/',Email,values[i]);
   end;
   drop i;
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 16 May 2023 18:00:39 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-05-16T18:00:39Z</dc:date>
    <item>
      <title>merge columns in the same dataset without duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876037#M346135</link>
      <description>&lt;P&gt;Hello.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to clean a dataset with several survey data merged, which means that the field "email" (and several others could be duplicated). I want to create just one variable without the duplicates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data example:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Email_1&lt;/TD&gt;&lt;TD&gt;Email_2&lt;/TD&gt;&lt;TD&gt;Email_3&lt;/TD&gt;&lt;TD&gt;Email_4&lt;/TD&gt;&lt;TD&gt;Email_5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;A href="mailto:TESTING@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING1@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING1@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;A href="mailto:TESTING2@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING2@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING2@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING2@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING2@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING2@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;A href="mailto:TESTING3@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING3@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING3@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING3@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING3@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING3@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want to get:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Email_1&lt;/TD&gt;&lt;TD&gt;Email_2&lt;/TD&gt;&lt;TD&gt;Email_3&lt;/TD&gt;&lt;TD&gt;Email_4&lt;/TD&gt;&lt;TD&gt;Email_5&lt;/TD&gt;&lt;TD&gt;Email&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;A href="mailto:TESTING@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING1@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING1@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING1@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING1@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;A href="mailto:TESTING2@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING2@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING2@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING2@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING2@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING2@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING2@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING2@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;A href="mailto:TESTING3@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING3@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING3@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING3@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING3@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING3@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING3@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING3@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found this code on the forum &lt;LI-MESSAGE title="Concatenation removing duplicates" uid="775174" url="https://communities.sas.com/t5/SAS-Programming/Concatenation-removing-duplicates/m-p/775174#U775174" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;Data test2;
   set test;
   array values (*) email_1-email_5;
   length Email $ 100 ;
   do i=1 to dim(values);
   if indexw(Email,values[i],'/')= 0 then Email= catx('/',Email,values[i]);
   end;
   drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But it concatenates with the "/", like this:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Email_1&lt;/TD&gt;&lt;TD&gt;Email_2&lt;/TD&gt;&lt;TD&gt;Email_3&lt;/TD&gt;&lt;TD&gt;Email_4&lt;/TD&gt;&lt;TD&gt;Email_5&lt;/TD&gt;&lt;TD&gt;Email&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;A href="mailto:TESTING@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING@NOWHERE.ORG/TESTING@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING@NOWHERE.ORG/TESTING@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING1@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING1@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING1@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING1@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;A href="mailto:TESTING2@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING2@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING2@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING2@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING2@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING2@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING2@NOWHERE.ORG/TESTING2@NOWHERE.ORG/TESTING2@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING2@NOWHERE.ORG/TESTING2@NOWHERE.ORG/TESTING2@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;A href="mailto:TESTING3@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING3@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING3@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING3@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING3@NOWHERE.ORG/TESTING3@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING3@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;TD&gt;&lt;A href="mailto:TESTING2@NOWHERE.ORG/TESTING2@NOWHERE.ORG/TESTING2@NOWHERE.ORG" target="_blank" rel="noopener"&gt;TESTING3@NOWHERE.ORG/TESTING3@NOWHERE.ORG/TESTING3@NOWHERE.ORG&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS EG 7.12 (7.100.2.3350) (64-bit)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 15:43:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876037#M346135</guid>
      <dc:creator>Scorpx</dc:creator>
      <dc:date>2023-05-16T15:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: merge columns in the same dataset without duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876044#M346140</link>
      <description>&lt;P&gt;This code needs a little modification:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data test2;
   set test;
   array values (*) email_1-email_5;
   length Email $ 100 ;
   Email= email_1;
   do i=2 to dim(values);
     	if values{i} ne values{1} then Email= catx('/',Email,values{i});
   end;
   drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 May 2023 16:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876044#M346140</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-05-16T16:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: merge columns in the same dataset without duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876064#M346150</link>
      <description>&lt;P&gt;Thank you for your response. However, it is still repeated and divided it using "/."&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 17:51:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876064#M346150</guid>
      <dc:creator>Scorpx</dc:creator>
      <dc:date>2023-05-16T17:51:43Z</dc:date>
    </item>
    <item>
      <title>Re: merge columns in the same dataset without duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876067#M346152</link>
      <description>&lt;P&gt;First thing I am concerned is that you show . in the example "data". That would typically mean in a SAS data set that the value of the variable is numeric and so INDEXW would not typically be appropriate.&lt;/P&gt;
&lt;P&gt;Second, you should show what you expect as a result when there are different values in at least some of the observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Third provide a data step with some example values. NOTE that the post you linked says "No data so untested".&lt;/P&gt;
&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;Data test2;
   set test;
   array values (*) email_1-email_5;
   length Email $ 125 ;
   do i=1 to dim(values);
      if indexw(strip(Email),strip(values[i]),'/')= 0 then Email= catx('/',Email,values[i]);
   end;
   drop i;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 May 2023 18:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876067#M346152</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-16T18:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: merge columns in the same dataset without duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876072#M346156</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;,&amp;nbsp;thank you for your response.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I appreciate your concerns, and you are probably bored of repeatedly answering the same questions, but I tried to be as specific as possible; your answer seems rude to me. Not because of what you said but how you say it, not all of us have the same level, and I appreciate the effort you and the rest of the community does to help us out; take into consideration that a bit of guidance is always well received.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Still, regarding what you mentioned:&lt;/P&gt;
&lt;P&gt;1. I Didn't know "INDEXW" didn't help; my data is not numeric as I showed in the "Example."&lt;/P&gt;
&lt;P&gt;2. It doesn't have different values (I checked them). However, in the rare case, it has a space or something that makes it appear different, I wouldn't mind having it repeated with "/".&lt;/P&gt;
&lt;P&gt;3. I'd like to do it, but those are emails, and I'd prefer to keep them private. I also read the note on the post; that's one of the reasons I wrote this one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Again, thank you for the time you took to answer my question. Have a great rest of your day.&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 18:18:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876072#M346156</guid>
      <dc:creator>Scorpx</dc:creator>
      <dc:date>2023-05-16T18:18:18Z</dc:date>
    </item>
    <item>
      <title>Re: merge columns in the same dataset without duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876076#M346160</link>
      <description>&lt;P&gt;Looks like missing values are captured as '.' instead of blanks. There might be hidden special characters as well. I've added STRIP and COMPRESS functions to eliminate '.'(dots) and hidden blanks&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    
Data test2;
   set have;
   array values (*) email_1-email_5;
   length Email $ 100 ;
   email= compress(email_1, '. ');
   do i=2 to dim(values);
		if strip(values{i}) ne '.' then Values{i}= strip(values{i}); 
		else Values{i}= '';
     	if compress(values{i}, '. ') ne compress(values{1}, '. ') then Email= catx('/',Email,values{i});
   end;
   drop i;
proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 19:11:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876076#M346160</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-05-16T19:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: merge columns in the same dataset without duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876080#M346163</link>
      <description>&lt;P&gt;Your description of what you want is not clear.&amp;nbsp; Do you want to pick just one email address?&amp;nbsp; If not do you want to write a separate observation for each unique email address?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also what are the rules for detecting duplicate email addresses? Are the email addresses case sensitive?&amp;nbsp; That is do you to treat "Joe@gmail.com" and "JOE@GMAIL.COM" as one email address or two?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not see any difference between your input and your output data.&amp;nbsp; &lt;STRONG&gt;Also what is with the periods in you data display?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's make some example data.&amp;nbsp; Let's keep some of those periods in the data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards dsd truncover;
  input (email_1-email_5) (:$char100.) ;
cards;
TESTING@NOWHERE.ORG,,TESTING@NOWHERE.ORG,,
,.,TESTING1@NOWHERE.ORG,.,
TESTING2@NOWHERE.ORG,TESTING2@NOWHERE.ORG,,TESTING2@NOWHERE.ORG,
TESTING3@NOWHERE.ORG,,.,TESTING3@NOWHERE.ORG,TESTING3@NOWHERE.ORG
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now let's loop over the source variables and only put new values into the temporary array.&lt;/P&gt;
&lt;P&gt;Then we can either concatenate the values into a single LOOONG variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  length email_list $500 ;
  set have ;
  array emails email_1-email_5;
  array temp [5] $100 _temporary_;
  do index=1 to dim(emails);
    if compress(emails[index],,'kad') ne ' ' then do;
      if emails[index] not in temp then temp[index]=emails[index];
    end;
  end;
  email_list = catx(';', of temp[*]) ;
  drop index ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    email_list                                         email_1           email_2

 1     TESTING@NOWHERE.ORG                          TESTING@NOWHERE.ORG
 2     TESTING@NOWHERE.ORG;TESTING1@NOWHERE.ORG                             .
 3     TESTING2@NOWHERE.ORG;TESTING1@NOWHERE.ORG    TESTING2@NOWHERE.ORG    TESTING2@NOWHERE.ORG
 4     TESTING3@NOWHERE.ORG;TESTING1@NOWHERE.ORG    TESTING3@NOWHERE.ORG

Obs    email_3                 email_4                       email_5

 1     TESTING@NOWHERE.ORG
 2     TESTING1@NOWHERE.ORG    .
 3                             TESTING2@NOWHERE.ORG
 4     .                       TESTING3@NOWHERE.ORG    TESTING3@NOWHERE.ORG

&lt;/PRE&gt;
&lt;P&gt;Or into multiple observations.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
  length email_number 8 email $100 ;
  set have ;
  array emails email_1-email_5;
  array temp [5] $100 _temporary_;
  do index=1 to dim(emails);
    if compress(emails[index],,'kad') ne ' ' then do;
      if emails[index] not in temp then temp[index]=emails[index];
    end;
  end;
  email_number=0;
  do index=1 to dim(temp);
    if temp[index] ne ' ' then do;
      email_number + 1;
      email = temp[index];
      output;
    end;
  end;
  drop index;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;  e
  m
  a
  i
  l
  _                               e                    e                    e                    e                    e
  n                               m                    m                    m                    m                    m
  u          e                    a                    a                    a                    a                    a
  m          m                    i                    i                    i                    i                    i
O b          a                    l                    l                    l                    l                    l
b e          i                    _                    _                    _                    _                    _
s r          l                    1                    2                    3                    4                    5

1 1 TESTING@NOWHERE.ORG  TESTING@NOWHERE.ORG                       TESTING@NOWHERE.ORG
2 1 TESTING@NOWHERE.ORG                       .                    TESTING1@NOWHERE.ORG .
3 2 TESTING1@NOWHERE.ORG                      .                    TESTING1@NOWHERE.ORG .
4 1 TESTING2@NOWHERE.ORG TESTING2@NOWHERE.ORG TESTING2@NOWHERE.ORG                      TESTING2@NOWHERE.ORG
5 2 TESTING1@NOWHERE.ORG TESTING2@NOWHERE.ORG TESTING2@NOWHERE.ORG                      TESTING2@NOWHERE.ORG
6 1 TESTING3@NOWHERE.ORG TESTING3@NOWHERE.ORG                      .                    TESTING3@NOWHERE.ORG TESTING3@NOWHERE.ORG
7 2 TESTING1@NOWHERE.ORG TESTING3@NOWHERE.ORG                      .                    TESTING3@NOWHERE.ORG TESTING3@NOWHERE.ORG
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 20:09:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876080#M346163</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-16T20:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: merge columns in the same dataset without duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876085#M346164</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/247746"&gt;@Scorpx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;,&amp;nbsp;thank you for your response.&lt;/P&gt;
&lt;P&gt;Still, regarding what you mentioned:&lt;/P&gt;
&lt;P&gt;2.&lt;FONT color="#FF00FF"&gt;&lt;STRONG&gt; It doesn't have different values&lt;/STRONG&gt;&lt;/FONT&gt; (I checked them). However, in the rare case, it has a space or something that makes it appear different, I wouldn't mind having it repeated with "/".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is a critical piece of information. That means that you really only want one value (which is quite different than the request of the post you linked). There is&amp;nbsp; a function that specifically returns the first non-missing value in a list: COALESCEC (or Coalesce for numeric variables)&lt;/P&gt;
&lt;P&gt;So to assign the first non-missing value to the variable email:&lt;/P&gt;
&lt;P&gt;email = coalescec(of email_:);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 20:31:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876085#M346164</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-16T20:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: merge columns in the same dataset without duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876089#M346166</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your response. Since I seem to be in error, please allow me to explain myself again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1.- I have five columns of emails (Email_1 - Email_5); they are capitalized to avoid the Joe or JOE or JoE, etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2.- Each row has the same email or none (because it is the same respondent/case, but a different survey); no column has every email.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3.- I want to have a column named "email" that collects each email to avoid having five different "Email_1, Email_2, Email_3..." so, instead of having 10,000 emails spread and repeated over five variables, I want to have just one variable with the 10,000 emails.&lt;/P&gt;
&lt;P&gt;4.- The output has this "email" column summarizing the emails.&lt;/P&gt;
&lt;P&gt;5.- Please think of the dots as blanks. (this want is my bad, apologies).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Scorpx_0-1684269491674.png" style="width: 1105px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/84030i8FF9ADD286A370D2/image-dimensions/1105x304?v=v2" width="1105" height="304" role="button" title="Scorpx_0-1684269491674.png" alt="Scorpx_0-1684269491674.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I hope I have given you a better description this time, I appreciate the help you are providing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 20:41:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876089#M346166</guid>
      <dc:creator>Scorpx</dc:creator>
      <dc:date>2023-05-16T20:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: merge columns in the same dataset without duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876092#M346167</link>
      <description>&lt;P&gt;This is the answer. Thank you. Yes, I wanted just one variable with one value:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As I mentioned:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;I want to create just one variable without the duplicates&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Next time I will try to provide better explanations.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your time.&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 20:52:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-columns-in-the-same-dataset-without-duplicates/m-p/876092#M346167</guid>
      <dc:creator>Scorpx</dc:creator>
      <dc:date>2023-05-16T20:52:02Z</dc:date>
    </item>
  </channel>
</rss>

