Hello
I have a variable called Plural in my dataset (numeric; 1-8; 9=unknown). Since for those w. Plural >1 will have duplicate values for the variables I am interested in, I want SAS to keep only one record (doesn't matter which) when Plural >1. Does anyone know how to do this?
Thank you!
Check next code:
proc sort data=have out=want nodupkey;
by DOB DATE1 PLURAL;
run;
Do you prefer the record with FEEDIN=YES or FEEDING=NO ?
If you have a preference then use next code:
proc sort data=have out=temp;
by DOB DATE1 PLURAL
{ascending or descending } FEEDING;
run;
data want;
set temp;
by DOB DATE1 PLURAL;
if first.plural;
run;
You haven't post test data.
You can use proc sort with option NODUPKEY to achieve one observation of
any plural occurence.
Thank you for your reply. But if I PROC SORT w. NODUPKEY by Plural SAS will get rid of the most obs because most of the obs in my dataset has Plural=1. I want SAS to pick one record only when Plural >1.
please post an example - some test data to explain what you have and the desired result.
ID DOB DATE1 DURATION PLURAL FEEDING
1 2/2/85 4/8/16 30 2 YES
2 2/2/85 4/8/16 30 2 NO
3 4/2/79 5/1/14 1 3
4 4/2/79 5/1/14 1 3 NO
5 4/2/79 5/1/14 1 3
6 8/1/12 5/1/16 10 1 NO
7 1/2/14 10/1/17 2 1
8 8/1/12 8/1/15 1 1 NO
So here's what my dataset kind of looks like.
ID and Feeding are collected from child. DOB, DATE1, DURATION, PLURAL are from mother. I am interested in the variable DURATION. Since DURATION is assigned to mother I'd like to keep only one record of this variable when Plural is greater than 1. If Plural=1 then there is only one record so I don't have to worry about it.
Hope this makes sense! Thank you!
Check next code:
proc sort data=have out=want nodupkey;
by DOB DATE1 PLURAL;
run;
Do you prefer the record with FEEDIN=YES or FEEDING=NO ?
If you have a preference then use next code:
proc sort data=have out=temp;
by DOB DATE1 PLURAL
{ascending or descending } FEEDING;
run;
data want;
set temp;
by DOB DATE1 PLURAL;
if first.plural;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: