BookmarkSubscribeRSS Feed
Smitha9
Fluorite | Level 6

Hi,

I have a dataset

ID  Sub_ID      Date

1      23        2020-06-01

1      24        2019-06-02

2      29        2015-05-04

2      33        2012-06-09

2      31        2014-09-09

 

I want to select the earliest Date of the SubID.

ID    SubID         Date

1       24          2019-06-02

2       33          2012-06-09

 

Can I do this is SAS? thanks in advance.

3 REPLIES 3
PaigeMiller
Diamond | Level 26
proc summary data=have nway;
    class id;
    var date;
    output out=want minid(date(sub_id))=subid min=;
run; 
--
Paige Miller
pink_poodle
Barite | Level 11
Proc sql;
select id, sub_id, min(date) as earliest_date
from have
where date ne .
group by id
having date = min(date)
;
quit;
ballardw
Super User

And another:

Proc sort data=have;
  by id date;
run;

data want;
   set have;
   by id;
   if first.id;
run;

When you use By processing in a data step SAS provides automatic variables that indicate whether a specific record is the first or last of a by group.