BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kiko
Fluorite | Level 6

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! 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

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;

View solution in original post

5 REPLIES 5
Shmuel
Garnet | Level 18

You haven't post test data.

You can use proc sort with option NODUPKEY to achieve one observation of

any plural occurence.

Kiko
Fluorite | Level 6

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. 

Shmuel
Garnet | Level 18

please post an example - some test data to explain what you have and the desired result.

Kiko
Fluorite | Level 6

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!

 

Shmuel
Garnet | Level 18

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;

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 9659 views
  • 0 likes
  • 2 in conversation