BookmarkSubscribeRSS Feed
vraj1
Quartz | Level 8

is there any way to pick "Y" from a variable with same id, 

 

I have a id variable and flag variable with multiple observations

 

101  Y

101   N

101  N

102 N

102 N

103 Y

 

is there a way where we can pick 101 and only "Y" from it and ignore "N" and in second id only take one record "N" and omitt the duplicate.

 

 

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Like this?

 

data have;
input id flag $;
datalines;
101 Y
101 N
101 N
102 N
102 N
103 Y
;

proc sort data=have;
	by id flag;
run;

data want;
	set have;
	if last.id;
run;
ballardw
Super User

If an ID has multiple Y flags what do you want for output? All N flags but more than 2 (your description does not actually cover this case as only mention similar for the second id. What if the 5th id has 4 flags?)

 

Best to provide an example of what the actual output should look like for given example input.

novinosrin
Tourmaline | Level 20

+1 @ballardw  Sir. I was gonna ask that question as I was wary too. You beat me.

 

Hello @vraj1   is there  a trick like,

 

Pick all Y's if multiples with an N or not,  and only distinct N if all N's?

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 475 views
  • 0 likes
  • 4 in conversation