SAS Enterprise Guide

Desktop productivity for business analysts and programmers
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
VarunD
Obsidian | Level 7

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
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;
VarunD
Obsidian | Level 7
Sincerely appreciate your help with this. Thanks again!
novinosrin
Tourmaline | Level 20

You're very welcome. Thank you for your questions 🙂

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1083 views
  • 1 like
  • 2 in conversation