I am analyzing survey data. I want to remove respondents that completed the survey more than once. A five-digit code was generated that enabled repeat responders to be identified (Variable name = privatecode).
I see various ways of using PROC SORT to remove duplicates and leave one observation (i.e. NODUPRECS, NODUPKEY). I want to remove ALL observations with the same private code.
How can I accomplish this?
Thanks!
Do you mean that you want to filter any privatecode if occures more than once ?
If so do:
proc sort data=have; by privatecode; run;
data want;
set have;
by privatecode;
if not (first.privatecode and last.privatecode) then delete;
run;
If by "filter" you mean remove, then yes!
There is one problem. Almost 400 observations have privatecode missing. These observations are being deleted because the privatecode is the same, missing.
What's the best work-around here?
Thanks!
if not (first.privatecode and last.privatecode) and not missing(privatecode) then delete;
In order to include all observations with missing privatecode, change my code to:
data want;
set have;
by privatecode;
if not (first.privatecode and last.privatecode)
and not missing(privatecode) then delete;
run;
Identify the singles and keep. Proc sql will do this:
proc sql; create table want as select b.* from ( select distinct privatecode from YOURDATESET group by privatecode having count(*)=1 ) as a left join YOURDATASET as b on a.private=b.privatecode; quit;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.