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
ID | Order of admission | Onset |
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 |
Data i want to keep
ID | Order of occurrence | Onset |
1 | 1 | 02/09/2011 |
1 | 2 | 04/30/2012 |
1 | 3 | 08/12/2013 |
2 | 1 | 07/27/2011 |
5 | 1 | 05/15/2011 |
5 | 2 | 08/22/2011 |
I am a beginner of SAS and use SAS 9.4. Please help me. Thanks in advance for the support.
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).
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).
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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.