<?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: Replace ALL duplicate observations with blanks in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493499#M15387</link>
    <description>Many, unfortunately. Someone put the average of a state data for many variables to fill missing for each county/city. I don't want to use the average, so need to get rid of them!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 07 Sep 2018 15:23:31 GMT</pubDate>
    <dc:creator>rj438</dc:creator>
    <dc:date>2018-09-07T15:23:31Z</dc:date>
    <item>
      <title>Replace ALL duplicate observations with blanks</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493405#M15369</link>
      <description>&lt;DIV class="lia-quilt-column lia-quilt-column-04 lia-quilt-column-left lia-quilt-column-main-left"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-quilt-column lia-quilt-column-20 lia-quilt-column-right lia-quilt-column-main-right"&gt;&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-right"&gt;&lt;DIV class="lia-message-heading lia-component-message-header"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P class="lia-message-dates lia-message-post-date lia-component-post-date-last-edited"&gt;Hi all,&lt;/P&gt;&lt;DIV class="lia-message-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that looks like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID V1 V2 V3&lt;/P&gt;&lt;P&gt;A&amp;nbsp; 12 13 14&lt;/P&gt;&lt;P&gt;A 12 14 14&lt;/P&gt;&lt;P&gt;A 12 15 14&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want it to look like:&lt;/P&gt;&lt;P&gt;ID V1 V2 V3&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp;13&amp;nbsp; &amp;nbsp;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp;14&amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp;15&amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;Basically, replace those with ID = A, and variables with duplicate values as missing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;if lag(ID)=ID and lag(V1)=V1 then call missing(V1);
if lag(ID)=ID&amp;nbsp;and lag(V2)=V2 then call missing(V2);
if lag(ID)=ID&amp;nbsp;and lag(V3)=V3 then call missing(V3);&lt;/PRE&gt;&lt;P&gt;I used this code but it only replaces subsequent duplicates, not all!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot for your help!&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 07 Sep 2018 13:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493405#M15369</guid>
      <dc:creator>rj438</dc:creator>
      <dc:date>2018-09-07T13:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Replace ALL duplicate observations with blanks</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493414#M15370</link>
      <description>&lt;P&gt;Well, it doesn't make much sense, but I would suggest flipping the data over:&lt;/P&gt;
&lt;PRE&gt;data have;
  input id $ v1 v2 v3;
datalines;
A 12 13 14
A 12 14 14
A 12 15 14
;
run;
proc transpose data=have out=inter;
  by id;
  var v:;
run;
data inter;
  set inter;
  array i col:;
  if sum(of i{*})/dim(i)=i{1} then call missing(of col:);
run;
proc transpose data=inter out=want;
  by id;
  var col:;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 13:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493414#M15370</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-07T13:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: Replace ALL duplicate observations with blanks</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493432#M15371</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;, i took the solution you posted from a different question, but wondering if there is any way to delete the original of the duplicates, and not just the subsequent ones!?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 13:54:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493432#M15371</guid>
      <dc:creator>rj438</dc:creator>
      <dc:date>2018-09-07T13:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: Replace ALL duplicate observations with blanks</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493434#M15372</link>
      <description>&lt;P&gt;Nothing about this post makes sense?&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 13:55:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493434#M15372</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-07T13:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: Replace ALL duplicate observations with blanks</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493443#M15373</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ V1 V2 V3;
cards;
A  12 13 14
A 12 14 14
A 12 15 14
;


proc means data=have noprint;
by id;
var v:;
output out=w(drop=_:) std=/autoname;
run;
data want;
merge have w;
by id;
array s1 v1-v3;
array s2 v1_stddev--v3_stddev;
do _n_=1 to dim(s1);
if s2(_n_)=0 then call missing(s1(_n_));
end;
keep id v1-v3;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Sep 2018 14:22:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493443#M15373</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-07T14:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: Replace ALL duplicate observations with blanks</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493448#M15374</link>
      <description>&lt;P&gt;What about this data?&amp;nbsp; What would you like the result to e for V1?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID V1 V2 V3&lt;/P&gt;
&lt;P&gt;A&amp;nbsp; &lt;FONT color="#FF0000"&gt;12&lt;/FONT&gt; 13 14&lt;/P&gt;
&lt;P&gt;A &lt;FONT color="#FF0000"&gt;15&lt;/FONT&gt;&amp;nbsp;14 14&lt;/P&gt;
&lt;P&gt;A &lt;FONT color="#FF0000"&gt;12&lt;/FONT&gt; 15 14&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 14:34:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493448#M15374</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-07T14:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: Replace ALL duplicate observations with blanks</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493467#M15375</link>
      <description>Anywhere that it's a duplicate should be deemed missing.&lt;BR /&gt;&lt;BR /&gt;ID V1 V2 V3&lt;BR /&gt;A . 13 .&lt;BR /&gt;A 15 14 .&lt;BR /&gt;A . 15 .&lt;BR /&gt;Thanks!</description>
      <pubDate>Fri, 07 Sep 2018 14:54:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493467#M15375</guid>
      <dc:creator>rj438</dc:creator>
      <dc:date>2018-09-07T14:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: Replace ALL duplicate observations with blanks</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493469#M15377</link>
      <description>&lt;P&gt;Why not just remove them from the data set?&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 14:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493469#M15377</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-07T14:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: Replace ALL duplicate observations with blanks</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493471#M15378</link>
      <description>&lt;P&gt;Sorry. It is to OP.&amp;nbsp; EDITED.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id $ v1 v2 v3;
datalines;
A  12 13 14
A 15 14 14
A 12 15 14
;
run;
proc sort data=have;
by id v1;
run;
data have;
 set have;
 by id v1;
 if not (first.v1 and last.v1) then call missing(v1);
run;

proc sort data=have;
by id v2;
run;
data have;
 set have;
 by id v2;
 if not (first.v2 and last.v2) then call missing(v2);
run;

proc sort data=have;
by id v3;
run;
data have;
 set have;
 by id v3;
 if not (first.v3 and last.v3) then call missing(v3);
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Sep 2018 15:09:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493471#M15378</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-09-07T15:09:30Z</dc:date>
    </item>
    <item>
      <title>Re: Replace ALL duplicate observations with blanks</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493478#M15379</link>
      <description>Because I want to keep the datapoints (either by obs or var) that are not duplicates. For instance, all the V2 datapoints for ID=A in this example.</description>
      <pubDate>Fri, 07 Sep 2018 15:03:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493478#M15379</guid>
      <dc:creator>rj438</dc:creator>
      <dc:date>2018-09-07T15:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: Replace ALL duplicate observations with blanks</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493481#M15380</link>
      <description>&lt;P&gt;Let me give you a solution that is straightforward and reliable, but tedious and time-consuming.&amp;nbsp; We will see if anyone comes up with a better solution.&amp;nbsp; (Hope somebody does!)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Process each variable separately:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by id v1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data temp;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by id v1;&lt;/P&gt;
&lt;P&gt;if first.v1=0 or last.v1=0 then v1=.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=temp;&lt;/P&gt;
&lt;P&gt;by id v2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data temp;&lt;/P&gt;
&lt;P&gt;set temp;&lt;/P&gt;
&lt;P&gt;by id v2;&lt;/P&gt;
&lt;P&gt;if first.v2=0 or last.v2=0 then v2=.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=temp;&lt;/P&gt;
&lt;P&gt;by id v3;&lt;/P&gt;
&lt;P&gt;run&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set temp;&lt;/P&gt;
&lt;P&gt;by id v3;&lt;/P&gt;
&lt;P&gt;if first.v3=0 or last.v3=0 then v3=.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 15:06:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493481#M15380</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-07T15:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: Replace ALL duplicate observations with blanks</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493486#M15383</link>
      <description>&lt;P&gt;This only returns one&amp;nbsp;observation per ID when I print the temp file. Am I missing something?&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 15:09:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493486#M15383</guid>
      <dc:creator>rj438</dc:creator>
      <dc:date>2018-09-07T15:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Replace ALL duplicate observations with blanks</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493488#M15384</link>
      <description>&lt;P&gt;Code is updated .&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 15:11:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493488#M15384</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-09-07T15:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: Replace ALL duplicate observations with blanks</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493495#M15386</link>
      <description>&lt;P&gt;Do you just have 3 vars v1-v3 or that could vary to many?&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 15:20:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493495#M15386</guid>
      <dc:creator>Andygray</dc:creator>
      <dc:date>2018-09-07T15:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: Replace ALL duplicate observations with blanks</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493499#M15387</link>
      <description>Many, unfortunately. Someone put the average of a state data for many variables to fill missing for each county/city. I don't want to use the average, so need to get rid of them!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 07 Sep 2018 15:23:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493499#M15387</guid>
      <dc:creator>rj438</dc:creator>
      <dc:date>2018-09-07T15:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: Replace ALL duplicate observations with blanks</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493515#M15389</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ V1 V2 V3;
cards;
A  12 13 14
A 15 14 14
A 12 15 14
;
data _have;
set have;
array t v:;
grp=_n_;
do i=1 to dim(t);
_v=t(i);
__v=vname(t(i));
output;
end;
keep id _: grp;
run;
proc sort data=_have out=w;
by id __v _v;
run;
data _w;
set w;
by id __v _v;
if not(first._v and last._v) then call missing(_v);
run;

proc sort data=_w out=_w1;
by id grp;
run;
proc transpose data=_w1 out=want(drop=grp _:);
by id grp;
var _v;
id __v;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Sep 2018 15:36:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493515#M15389</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-07T15:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: Replace ALL duplicate observations with blanks</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493516#M15390</link>
      <description>&lt;P&gt;Here is a Hash Table solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id $ v1 v2 v3;
  n+1;
datalines;
A  12 13 14
A 15 14 14
A 12 15 14
;
run;
proc transpose data=have out=temp;
by id n;
var v:;
run;
proc sort data=temp nouniquekey;
by id _name_ col1;
run;

data want;
 if _n_=1 then do;
   if 0 then set temp;
   declare hash h(dataset:'temp');
   h.definekey('id','_name_','col1');
   h.definedone();
 end;
set have;
array x{*} v:;
do i=1 to dim(x);
 _name_=vname(x{i});col1=x{i};
 if h.check()=0 then call missing(x{i});
end;
drop i n  _name_ col1;
run;


proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Sep 2018 15:36:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493516#M15390</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-09-07T15:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: Replace ALL duplicate observations with blanks</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493523#M15391</link>
      <description>I think this was the quickest (albeit twisted) solution to my problem, thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;!</description>
      <pubDate>Fri, 07 Sep 2018 15:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Replace-ALL-duplicate-observations-with-blanks/m-p/493523#M15391</guid>
      <dc:creator>rj438</dc:creator>
      <dc:date>2018-09-07T15:50:21Z</dc:date>
    </item>
  </channel>
</rss>

