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

I need to limit one admission per year, there can be multiple admissions for that one patient. I want to look across all admissions and then select one admission per year. Thank you!

 

Patient CAdm 114-Jan-16Include first admission
Patient CAdm 26-May-17Include (more than 365 days)
Patient CAdm 35-Jun-17Exclude (less than 365 days from Adm 2)
Patient DAdm 114-Jan-16Include first admission
Patient DAdm 26-Jan-17Exclude (less than 365 days from Adm 1)
Patient DAdm 35-Jun-17Include (more than 365 days from Adm 1)
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @analyst_work  Thank you

 



data have;
infile cards truncover;
input patient & $20. adm & $6. date :date9.;*  out_date :date9.;
format date date9.  ;*out_date date9.;
cards;
Patient C	Adm 1	14-Jan-16	Include first admission
Patient C	Adm 2	6-May-17	Include (more than 365 days)
Patient C	Adm 3	5-Jun-17	Exclude (less than 365 days from Adm 2)
Patient D	Adm 1	14-Jan-16	Include first admission
Patient D	Adm 2	6-Jan-17	Exclude (less than 365 days from Adm 1)
Patient D	Adm 3	5-Jun-17	Include (more than 365 days from Adm 1)
;




data want;
set have;
by patient;
retain d;
if first.patient then do; d=date;f=1;end;
else if intck('day',d,date)>365 then do;
d=date;
f=1;
end;
if f;
drop f d;
run;

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

You have two different date variables here. What dates are to be considered? The to date from adm1 and the from date from adm2?

analyst_work
Obsidian | Level 7
Updated the table above. Thanks!
novinosrin
Tourmaline | Level 20

Hi @analyst_work   Please review 

 

Patient D Adm 1 12-Jan-16 14-Jan-16 Include first admission
Patient D Adm 2 6-May-17 6-Jan-17 Exclude (less than 365 days from Adm 1)

 

How is the number of days between  14-Jan-16 and 6-May-17 is less than 365?

 

EDITED: Please ignore this post

analyst_work
Obsidian | Level 7
Please see updated table above. Thanks!
novinosrin
Tourmaline | Level 20

Hi @analyst_work  Thank you

 



data have;
infile cards truncover;
input patient & $20. adm & $6. date :date9.;*  out_date :date9.;
format date date9.  ;*out_date date9.;
cards;
Patient C	Adm 1	14-Jan-16	Include first admission
Patient C	Adm 2	6-May-17	Include (more than 365 days)
Patient C	Adm 3	5-Jun-17	Exclude (less than 365 days from Adm 2)
Patient D	Adm 1	14-Jan-16	Include first admission
Patient D	Adm 2	6-Jan-17	Exclude (less than 365 days from Adm 1)
Patient D	Adm 3	5-Jun-17	Include (more than 365 days from Adm 1)
;




data want;
set have;
by patient;
retain d;
if first.patient then do; d=date;f=1;end;
else if intck('day',d,date)>365 then do;
d=date;
f=1;
end;
if f;
drop f d;
run;
ballardw
Super User

@analyst_work wrote:

I need to limit one admission per year, there can be multiple admissions for that one patient. I want to look across all admissions and then select one admission per year. Thank you!

 

Patient C Adm 1 14-Jan-16 Include first admission
Patient C Adm 2 6-May-17 Include (more than 365 days)
Patient C Adm 3 5-Jun-17 Exclude (less than 365 days from Adm 2)
Patient D Adm 1 14-Jan-16 Include first admission
Patient D Adm 2 6-Jan-17 Exclude (less than 365 days from Adm 1)
Patient D Adm 3 5-Jun-17 Include (more than 365 days from Adm 1)

Any other rules? Is this supposed to be a random selection? First within period?

 

And do you actually have SAS date values or are your values currently character values that resemble dates?

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1610 views
  • 0 likes
  • 4 in conversation