Monday, 10 October 2011

SAS - Reporting Duplicate sql


/*repoting duplicates-frequency,nodupe key,first.variable*/

data mh;
input pid visit dose;
cards;
101 1 0.05
102 1 0.1
103 1 0.15
103 1 0.15
101 2 0.05
103 2 0.15
101 2 0.05
103 2 0.15
101 2 0.15
102 3 0.1
103 3 0.2
;

proc sql;
select pid,count(pid) as frq 'no of visits' from mh
group by pid having frq>3 or frq<3;
quit;

proc sql;
select visit,count(visit) as frq 'no of visits' from mh
group by visit having frq>3 or frq<3;
quit;

proc sql;
select pid,visit,count(visit) as frq 'no of times' from mh
group by pid,visit ;
quit;

proc sql;
select pid,visit,dose,count(dose) as frq 'no of times' from mh
group by pid,visit,dose ;
quit;

/*report duplicate data values*/
data employ;
input eid des $;
cards;
101 tester
102 analyst
102 programer
103 tester
104 analyst
104 tester
;

proc sql;
select eid,count(eid) as frq from employ
group by eid having frq>1;
quit;

proc sql;
select * from employ where eid in(select eid from employ
group by eid having  count(eid)>1);
quit;

/*duplicate obsrvations*/
proc sql;
select pid,visit,count(visit) as frq  from mh
group by pid,visit having frq>1 ;
quit;

No comments:

Post a Comment