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) |
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;
You have two different date variables here. What dates are to be considered? The to date from adm1 and the from date from adm2?
Hi @analyst_work Please review
How is the number of days between 14-Jan-16 and 6-May-17 is less than 365?
EDITED: Please ignore this post
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;
@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?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.