Hello,
Please help me with the code for the following problem:
Data: MEMBER TABLE
MemberID          Group        County           AddressType
      A                    111           Newman              H
      A                    111           Fritz                     M
      A                    111            Damus                 I
      B                    114           Holler                  H
      C                    114           Boxing                H
      D                    114           Dockers              M
I want to select observations on the following basis:
1.) When MemberID is same under a particular Group then select/get the observation with AddressType 'H'
2.) When MemberID is different under a particular Group then select/get all the observations.
Here is what I am hoping to get:
MemberID          Group        County           AddressType
      A                    111           Newman              H
      B                    114           Holler                  H
      C                    114           Boxing                H
      D                    114           Dockers              M
Thanks,
Varun
data have;
input MemberID     $     Group        County    $       AddressType $;
cards;
      A                    111           Newman              H
      A                    111           Fritz                     M
      A                    111            Damus                 I
      B                    114           Holler                  H
      C                    114           Boxing                H
      D                    114           Dockers              M
	  ;
proc sql;
create table want(drop=t) as
select *,count(distinct memberid)>1 as t
from have
group by group
having (not t and AddressType='H') or t ;
quit;
data have;
input MemberID     $     Group        County    $       AddressType $;
cards;
      A                    111           Newman              H
      A                    111           Fritz                     M
      A                    111            Damus                 I
      B                    114           Holler                  H
      C                    114           Boxing                H
      D                    114           Dockers              M
	  ;
proc sql;
create table want(drop=t) as
select *,count(distinct memberid)>1 as t
from have
group by group
having (not t and AddressType='H') or t ;
quit;
You're very welcome. Thank you for your questions 🙂
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.
