<?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: Removing repeat IDs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Removing-repeat-IDs/m-p/403400#M98031</link>
    <description>&lt;P&gt;Making some assumptions about the format of the data and the variables you want to keep in the output this should give you what&amp;nbsp;you're asking for&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	length id $1 repeat 8. firstid $3;
	infile datalines dlm='09'x missover truncover;
	input id repeat firstid;
	datalines;
1	0
2	0
3	1	2
4	0
5	0
6	1	4,5
;
run;

proc sql;
	create table repeats
	as select firstid
	from have
	where firstid ne "";
quit;

data repeatslong(keep=id);
	set repeats;
	if count(firstid,",") &amp;gt; 0 then do;
		do i = 1 to (count(firstid,",")+1);
			id=scan(firstid,i,",");
			output;
		end;
	end;
	else do;
		id=firstid;
		output;
	end;
run;

proc sql;
	create table want
	as select id, repeat
	from have
	where id not in
		(select id
		 from repeatslong)
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Oct 2017 00:32:29 GMT</pubDate>
    <dc:creator>ChrisBrooks</dc:creator>
    <dc:date>2017-10-12T00:32:29Z</dc:date>
    <item>
      <title>Removing repeat IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-repeat-IDs/m-p/403367#M98015</link>
      <description>&lt;P&gt;I have a data set structured as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; repeat&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; firstID&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4,5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I need to keep only the new IDs for patients who were repeats. In this example, I would need to remove 2, 4, 5. Some have multiple previous IDs, so there is a comma separating them. What is the most efficient way to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 21:10:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-repeat-IDs/m-p/403367#M98015</guid>
      <dc:creator>Melk</dc:creator>
      <dc:date>2017-10-11T21:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: Removing repeat IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-repeat-IDs/m-p/403400#M98031</link>
      <description>&lt;P&gt;Making some assumptions about the format of the data and the variables you want to keep in the output this should give you what&amp;nbsp;you're asking for&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	length id $1 repeat 8. firstid $3;
	infile datalines dlm='09'x missover truncover;
	input id repeat firstid;
	datalines;
1	0
2	0
3	1	2
4	0
5	0
6	1	4,5
;
run;

proc sql;
	create table repeats
	as select firstid
	from have
	where firstid ne "";
quit;

data repeatslong(keep=id);
	set repeats;
	if count(firstid,",") &amp;gt; 0 then do;
		do i = 1 to (count(firstid,",")+1);
			id=scan(firstid,i,",");
			output;
		end;
	end;
	else do;
		id=firstid;
		output;
	end;
run;

proc sql;
	create table want
	as select id, repeat
	from have
	where id not in
		(select id
		 from repeatslong)
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 00:32:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-repeat-IDs/m-p/403400#M98031</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-10-12T00:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: Removing repeat IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-repeat-IDs/m-p/403409#M98033</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/140721"&gt;@Melk&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;I tend to use SAS hash tables to create black-lists or white-lists. Below an example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	length id $1 repeat 8. firstid $3;
	infile datalines dlm='09'x truncover;
	input id repeat firstid;
	datalines;
1	0
2	0
3	1	2
4	0
5	0
6	1	4,5
;
run;

data want(drop=_:);

  if _n_=1 then
    do;
      dcl hash h1();
      h1.defineKey('id');
      h1.defineDone();

      do until(last);
        set have(keep=firstid) end=last;
        if not missing(firstid) then
          do _i=1 by 1;
            id=scan(firstid,_i,',');
            if missing(id) then leave;
            h1.ref();
          end;
      end;
    end;

    set have;
    if h1.check() then output;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 01:18:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-repeat-IDs/m-p/403409#M98033</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-10-12T01:18:56Z</dc:date>
    </item>
    <item>
      <title>Re: Removing repeat IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-repeat-IDs/m-p/403494#M98054</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/140721"&gt;@Melk&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;You can also do it with a relatively simple datastep solution:&lt;/P&gt;&lt;PRE&gt;data have;
  length id $1 repeat 8. firstid $3;
  infile cards truncover;
  input id repeat firstid;
cards;
1 0
2 0
3 1 2
4 0
5 0
6 1 4,5
;
run;

data drop;
  set have;
  where firstid;&lt;BR /&gt;  /* parse firstid */
  do _N_=1 to countw(firstid,',');&lt;BR /&gt;    id=scan(firstid,_N_,',');
    output;
    end;
  keep id;
run;

proc sort data=drop;
  by id;
run;

data want;
  merge have drop(in=drop);
  by id;
  if not drop;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Oct 2017 11:16:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-repeat-IDs/m-p/403494#M98054</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-10-12T11:16:03Z</dc:date>
    </item>
  </channel>
</rss>

