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.

 

 

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 736 views
  • 4 likes
  • 4 in conversation