BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
htht
Calcite | Level 5

Hi all,

I had this situation where I choose the onset date ranging from 01/01/2011 to 12/31/2011 and follow up until 12/31/2013. Therefore I need to exclude all the ID's with onset after 12/31/2011 on the first observation. For example, in the below scenario there are multiple observations for each ID.  I want to delete all those ID's which had first onset occur after 12/31/2011. 

Data I have

IDOrder of admissionOnset
1102/09/2011
1204/30/2012
1308/12/2013
2107/27/2011
3105/11/2012
3212/25/2012
4111/09/2013
5105/15/2011
5208/22/2011

Data i want to keep

IDOrder of occurrenceOnset
1102/09/2011
1204/30/2012
1308/12/2013
2107/27/2011
5105/15/2011
5208/22/2011

 I am a beginner of SAS and use SAS 9.4. Please help me. Thanks in advance for the support. 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
data want;
set have;
by id;
retain _keep;
if first.id then _keep = (onset lt "31dec2011"d);
if _keep;
drop _keep;
run;

Untested, posted from my tablet; for tested code, supply example data in usable form (data step with datalines).

View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User
data want;
set have;
by id;
retain _keep;
if first.id then _keep = (onset lt "31dec2011"d);
if _keep;
drop _keep;
run;

Untested, posted from my tablet; for tested code, supply example data in usable form (data step with datalines).

htht
Calcite | Level 5
Dear KurtBremser,
I am so sorry for this. This is my datalines:

data have;
input ID Order_of_admission $onset: mmddyy10.;
format onset mmddyy10.;
cards;
1 1 02/09/2011
1 2 04/30/2012
1 3 08/12/2013
2 1 07/27/2011
3 1 05/11/2012
3 2 12/25/2012
4 1 11/09/2013
5 1 05/15/2011
5 2 08/22/2011
;
run;
novinosrin
Tourmaline | Level 20

data have;
input ID Order_of_admission $onset: mmddyy10.;
format onset mmddyy10.;
cards;
1 1 02/09/2011
1 2 04/30/2012
1 3 08/12/2013
2 1 07/27/2011
3 1 05/11/2012
3 2 12/25/2012
4 1 11/09/2013
5 1 05/15/2011
5 2 08/22/2011
;
run;

proc sql;
create table want as
select *
from have
group by id	
having not min(onset)>'31dec2011'd
order by id, order_of_admission;
quit;
htht
Calcite | Level 5
Hi KurtBremser,
Thank you so much. After class, I checked code in my real data and perfect.
You helped me to solve it.
Thank you.
htht
Calcite | Level 5
I just change a little from "lt" to "le".
Thank you.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 526 views
  • 0 likes
  • 3 in conversation