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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1010 views
  • 0 likes
  • 4 in conversation