Help using Base SAS procedures

Keep records that are duplicated - remove unique records

Accepted Solution Solved
Reply
Super Contributor
Posts: 297
Accepted Solution

Keep records that are duplicated - remove unique records

[ Edited ]

Hello ,

I want to create data "B" from data "A". That is , I want to keep only data with at least two time points;

 

Data a,
Input id timepoint;
Cards;
001     1
001     2
001     3
002    1
003    1
003    2
004    1
005    1
;
 
Run;

 

 

 Data "B" is created from data "A". id 002 , 004 and 005 are dropped because they are just one time points.

 

 

Data B;
Input id timepoint;
Cards;
 
001     1
001     2
001     3
 
003    1
003    2
;
run;

 

 


Accepted Solutions
Solution
‎05-07-2017 05:07 PM
Super User
Posts: 17,836

Re: Keep records that are duplicated - remove unique records

You can use the NOUNIQUEKEY option on PROC SORT.

 

proc sort
     data = sashelp.adomsg
          out = duplicates
          uniqueout = singles
          nouniquekey;
     by msgid;
run;

View solution in original post


All Replies
PROC Star
Posts: 172

Re: reduce a data base on time point

proc sql;

create table b as

select *

from a

group by id

having count(id)>1;

quit;

Super Contributor
Posts: 297

Re: reduce a data base on time point

Thanks

Solution
‎05-07-2017 05:07 PM
Super User
Posts: 17,836

Re: Keep records that are duplicated - remove unique records

You can use the NOUNIQUEKEY option on PROC SORT.

 

proc sort
     data = sashelp.adomsg
          out = duplicates
          uniqueout = singles
          nouniquekey;
     by msgid;
run;
Trusted Advisor
Posts: 1,129

Re: Keep records that are duplicated - remove unique records

With datastep as well

 


data a2;
do until(last.id);
set a;
by id timepoint;
if first.id then count=1;
else count+1;
end;
do until(last.id);
set a;
by id timepoint;
if count>1 then output ;
end;
run;

 
Thanks,
Jag
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 219 views
  • 1 like
  • 4 in conversation