Hi I want to flag diagnosis codes during defined study period
DM dignosis pt ID From_dt To-Dt
1 (yes) 1 2005-04-02 2006-05-20
2(yes) 2 2001-01-01 2001-01-02
Study period index_dt end_dt
2004-04-01 2007-01-10
I want my result to look like;
Pt ID eligible
1 yes
2 no
Thanks
Post test data in the form of a datastep. I haven't time to type that in or guess what formats etc the table has. So at a rough guess:
proc sql; create table WANT as select A.PT_ID, case when A.FROM_DT <= B.END_DT and A.TO_DT > B.INDEX_DT then "yes" else "no" end as ELIGIBLE from HAVE1 A left join HAVE2 B on 1=1; quit;
You can do the same thing in datastep merge also, basically your merging the dates dataset onto the main one, then doing an if between the two dates.
Hi,
I need to clarify my initial question. It had mistakes. My variables are all from the same dataset and dates are already SAS dates
So
DM_diagnosis pt ID from_dt (diag) To_dt (diag) Index_dt end_dt
1 (yes) 1 2005-04-02 2006-05-20 2004-04-01 2007-01-10
1 (yes) 2 2001-01-01 2001-01-02 2003-04-01 2003-12-10
Output
Pt ID eligible
1 yes
2 no
Thanks
Even simpler then, you just need the if statements:
data want; set have; if from_dt <= end_dt and to_dt >= index_dt then eligible="yes"; else eligible="no"; run;
@leahcho wrote:
Hi,
I need to clarify my initial question. It had mistakes. My variables are all from the same dataset and dates are already SAS dates
So
DM_diagnosis pt ID from_dt (diag) To_dt (diag) Index_dt end_dt
1 (yes) 1 2005-04-02 2006-05-20 2004-04-01 2007-01-10
1 (yes) 2 2001-01-01 2001-01-02 2003-04-01 2003-12-10
Output
Pt ID eligible
1 yes
2 no
Thanks
You may need to provide some additional rules. Is it within study period if the from_dt is prior to the index date but the to_dt is in the interval?
If the from_dt is before and To_dt is past the end_dt (the study interval is within the diag interval)
How about the from_dt is in the interval but the to_dt is past the end_dt?
I want diagnosis interval to fall within study interval
Thanks
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.