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.
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;
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.