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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 338 views
  • 4 likes
  • 4 in conversation