<?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: Double value elimination on one cell in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919151#M362048</link>
    <description>&lt;P&gt;I don't think so, because there are other columns that have to piggyback without change.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Mar 2024 16:36:58 GMT</pubDate>
    <dc:creator>melassiri</dc:creator>
    <dc:date>2024-03-06T16:36:58Z</dc:date>
    <item>
      <title>Double value elimination on one cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919069#M362015</link>
      <description>&lt;P&gt;you have column A with multiple values separated by comas and some values appear more than once in a cell.&lt;BR /&gt;How can you copy column A into column B without duplicate values .&lt;BR /&gt;For example. in column A:&lt;BR /&gt;A1 = a, b&lt;BR /&gt;A2 =&lt;BR /&gt;A3 = c, b, c&lt;BR /&gt;A4 = a, b, b,c,a&lt;BR /&gt;A5 = d&lt;BR /&gt;Column B would be:&lt;BR /&gt;B1 = a, b&lt;BR /&gt;B2 =&lt;BR /&gt;B3 = c, b&lt;BR /&gt;B4 = a, b, c&lt;BR /&gt;B5 = d&lt;BR /&gt;Please provide examples.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 11:13:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919069#M362015</guid>
      <dc:creator>melassiri</dc:creator>
      <dc:date>2024-03-06T11:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: Double value elimination on one cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919072#M362017</link>
      <description>&lt;P&gt;This looks like an Excel question. Is it?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 11:18:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919072#M362017</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-03-06T11:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: Double value elimination on one cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919075#M362019</link>
      <description>&lt;P&gt;For a SAS table something like below should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input a $10.;
  datalines;
a, b

c, b, c
a, b, b,c,a
d
;

data want(drop=_:);
  set have;
  array words{100} $10 _temporary_;
  length _word $10;

  b=a;
  do _i=1 to dim(words) until(missing(_word));
    _word=scan(b,_i,',');
    if whichc(_word,of words[*])=0 then words{_i}=_word;
  end;
  b=catx(',',of words[*]);
  call missing(of words[*]);
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&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="Patrick_0-1709726168916.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94410i8DB9CCBABA262A8D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1709726168916.png" alt="Patrick_0-1709726168916.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 12:00:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919075#M362019</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-06T12:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: Double value elimination on one cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919083#M362020</link>
      <description>&lt;P&gt;You should ask this in an Excel-oriented forum.&lt;/P&gt;
&lt;P&gt;With a SAS dataset, I would first expand this to a vertical layout, after which a SORT with NODUPKEY will do it.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 12:09:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919083#M362020</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-03-06T12:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: Double value elimination on one cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919151#M362048</link>
      <description>&lt;P&gt;I don't think so, because there are other columns that have to piggyback without change.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 16:36:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919151#M362048</guid>
      <dc:creator>melassiri</dc:creator>
      <dc:date>2024-03-06T16:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: Double value elimination on one cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919152#M362049</link>
      <description>I don't think so, because there are other columns that have to piggyback without change.</description>
      <pubDate>Wed, 06 Mar 2024 16:37:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919152#M362049</guid>
      <dc:creator>melassiri</dc:creator>
      <dc:date>2024-03-06T16:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: Double value elimination on one cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919153#M362050</link>
      <description>&lt;P&gt;thank you for your help. I appreciate that&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 16:40:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919153#M362050</guid>
      <dc:creator>melassiri</dc:creator>
      <dc:date>2024-03-06T16:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: Double value elimination on one cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919164#M362056</link>
      <description>&lt;P&gt;You could try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input a $10.;
  datalines;
a, b

c, b, c
a, b, b,c,a
d
;
run;

filename f TEMP;
data _null_; file f; put; run;

%let N=20; /* expected max number of elements */

data want;
  infile f dlm=" ," truncover;
  set have;

  input @@;
  _infile_ = a;
  input @1 (n1-n&amp;amp;N.) (:$1.) @@;

  array n(i) n:;
  array m[&amp;amp;N.] $ 1;

  do over n;
    if n NE " " AND NOT (n IN m) then m(i) = n;
  end;

  b = catx(",", of m[*]);
  keep a b;
run;

filename f clear;


proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Filename&amp;nbsp; and data _null_ is just a "fake" to trick the infile statement in the data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In data want logic is the following:&lt;/P&gt;
&lt;P&gt;1) convince SAS it will be reading a text file&lt;/P&gt;
&lt;P&gt;2) read data form HAVE&lt;/P&gt;
&lt;P&gt;3) pretend you are reading text file&lt;/P&gt;
&lt;P&gt;4) replace the buffer with your variable value&lt;/P&gt;
&lt;P&gt;5) re-read the buffer and create &amp;amp;N. character variables&lt;/P&gt;
&lt;P&gt;6) initiate arrays of n's and m's of the same size &amp;amp;N.&lt;/P&gt;
&lt;P&gt;7) loop over array N,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt; if variable N is not missing and is not in array M add it to M&lt;/P&gt;
&lt;P&gt;9) catX M variables into comma separated string&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[EDIT:] that sunglasses face &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt; should be "eight &amp;amp; closing parenthesis"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2024 17:22:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919164#M362056</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-03-06T17:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: Double value elimination on one cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919221#M362072</link>
      <description>&lt;P&gt;You could scan each "word" (i.e. each comma-separated value) in A and add it to B if it isn't already there:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input a $10.;
  datalines;
a, b
c, b, c
a, b, b,c,a
d
;

data want (drop=w word);
  set have;
  length b $10;
  do w=1 to countw(a,',');
    word=scan(a,w,', ');
    if findw(b,trim(word),', ')=0 then b=catx(',',b,word);
  end;
  b=transtrn(b,',',', ');  *Keep this if you want blanks after commas *;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2024 01:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919221#M362072</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-03-07T01:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Double value elimination on one cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919225#M362074</link>
      <description>&lt;P&gt;If you allow to sort the content of column A, then prxchange can be used:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input a $11.;
  datalines;
a, b

c, b, c
a, b, b,c,a
d
;

data want;
  set have;

  array _dummy_[100] $1 _temporary_;
  call missing(of _dummy_[*]);
  cmpres_a=compress(a,' ,');
  call pokelong(cmpres_a,addrlong(_dummy_[1]),length(cmpres_a));
  call sort(of _dummy_[*]);
  new_a=prxchange('s/\b(\w), (\1)\b/$1/',-1,catx(', ',of _dummy_[*]));
  put new_a=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result will be:&lt;/P&gt;
&lt;PRE&gt;new_a=a, b
new_a=
new_a=b, c
new_a=a, b, c
new_a=d
&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Mar 2024 02:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919225#M362074</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2024-03-07T02:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Double value elimination on one cell</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919238#M362082</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/461768"&gt;@melassiri&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I don't think so, because there are other columns that have to piggyback without change.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why would that matter?&amp;nbsp; When you expand the comma separated list into multiple observations they will all have the exact same values for the "other" variables.&amp;nbsp; So when you collapse them again (if you ever need to) there is no problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course it is easiest if the there is a simple BY variable (or perhaps a couple) that uniquely identify the original observations.&amp;nbsp; Of course you can always add one while you expand to multiple observations.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tall;
  id+1;
  set have;
  do i=1 to max(1,countw(A,','));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;value&amp;nbsp;=&amp;nbsp;strip(scan(A,i,',&amp;nbsp;'));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;output;&amp;nbsp;
&amp;nbsp;&amp;nbsp;end;
&amp;nbsp;&amp;nbsp;drop&amp;nbsp;i ;
run;
proc&amp;nbsp;sort&amp;nbsp;data=tall&amp;nbsp;nodupkey&amp;nbsp;out=want;
&amp;nbsp;&amp;nbsp;by&amp;nbsp;id&amp;nbsp;value;
run;
data&amp;nbsp;want;
&amp;nbsp;&amp;nbsp;do&amp;nbsp;until(last.id);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set&amp;nbsp;want;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;by&amp;nbsp;id;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;length&amp;nbsp;B&amp;nbsp;$100;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;b&amp;nbsp;=&amp;nbsp;catx(',',b,value);
&amp;nbsp;&amp;nbsp;end;
  drop value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2024 05:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Double-value-elimination-on-one-cell/m-p/919238#M362082</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-07T05:18:55Z</dc:date>
    </item>
  </channel>
</rss>

