Help using Base SAS procedures

Proc SQL Group By Question

Reply
N/A
Posts: 0

Proc SQL Group By Question

Hello All,
I hope you can help me on this. In my dataset I have siblings and their addresses. I am trying to group all siblings by address, so I know all the siblings who reside at an address. Now in this group I only want to pick the youngest sibling and get that information. I am trying to do this in EG, I have the dataset sorted by mailing address, but I would like to know is there a way where I can get the youngest sibling in the group. (something like select top 1)
Here is my dataset

Address name age
111 street1 child1 5
111 street1 child2 10

In this group I only want to output info for
child1





Thanks for any help
Shri
Regular Contributor
Posts: 165

Re: Proc SQL Group By Question

Posted in reply to deleted_user
I think this would be much easier in a data step after you sort by address and age and then use first.address with by group processing to find the youngest.

Good luck!
PROC Star
Posts: 7,468

Re: Proc SQL Group By Question

Posted in reply to deleted_user
Shri,

What do you want to do if the youngest are twins? If you don't confront any twins, or want multiple records in such a case, you could try something like:

proc sql noprint;
create table want as
select *
from have
group by Address
having age eq min(age)
;
quit;

HTH,
Art
Ask a Question
Discussion stats
  • 2 replies
  • 301 views
  • 0 likes
  • 3 in conversation