Hi Folks,
I'm trying to subset data where
1. year(date_diagnosis)=year(claim_date)
and
2. Oct, Nov and Dec of year before and Jan, Feb and Mar of year after the year(claim_date) to account for border months.
Desired output is the data with variable mark (1,0) where 1 indicating the data I'm gonna keep.
Thanks for help. I greatly appreciate your time.
DATA HAVE;
format PAT_ID 1. CLAIM_DATE date9. YEAR 4. MARK 1.;
informat CLAIM_DATE date9. YEAR 4. MARK 1.;
input PAT_ID CLAIM_DATE YEAR MARK;
CARDS;
1 27-Dec-08 2011 0
1 19-Dec-09 2011 0
1 1-Jun-10 2011 0
1 1-Oct-10 2011 1
1 15-Nov-10 2011 1
1 1-Aug-11 2011 1
1 3-Jan-12 2011 1
1 5-Jan-12 2011 1
1 29-Dec-12 2011 0
2 2-May-14 2014 1
2 15-Oct-14 2014 1
2 13-Jan-15 2014 1
2 1-Feb-15 2014 1
2 18-Mar-15 2014 1
2 30-Sep-15 2014 0
2 1-Oct-15 2014 0
3 27-Dec-08 2011 0
3 15-Dec-09 2011 0
3 1-Jun-10 2011 0
3 1-Oct-10 2011 1
3 15-Nov-10 2011 1
3 1-Aug-11 2011 1
3 3-Jan-12 2011 1
3 2-Apr-12 2011 0
3 23-Nov-15 2011 0
3 5-Oct-16 2011 0
;
data have1; set have;
claim_year=year(claim_date);
claim_month=month(claim_date);
run;
proc print data=have1; run;
DATA HAVE;
format PAT_ID 1. CLAIM_DATE date9. YEAR 4. ;
informat CLAIM_DATE date9. YEAR 4. MARK 1.;
input PAT_ID CLAIM_DATE YEAR MARK;
drop mark;
CARDS;
1 27-Dec-08 2011 0
1 19-Dec-09 2011 0
1 1-Jun-10 2011 0
1 1-Oct-10 2011 1
1 15-Nov-10 2011 1
1 1-Aug-11 2011 1
1 3-Jan-12 2011 1
1 5-Jan-12 2011 1
1 29-Dec-12 2011 0
2 2-May-14 2014 1
2 15-Oct-14 2014 1
2 13-Jan-15 2014 1
2 1-Feb-15 2014 1
2 18-Mar-15 2014 1
2 30-Sep-15 2014 0
2 1-Oct-15 2014 0
3 27-Dec-08 2011 0
3 15-Dec-09 2011 0
3 1-Jun-10 2011 0
3 1-Oct-10 2011 1
3 15-Nov-10 2011 1
3 1-Aug-11 2011 1
3 3-Jan-12 2011 1
3 2-Apr-12 2011 0
3 23-Nov-15 2011 0
3 5-Oct-16 2011 0
;
data want;
set have;
by pat_id;
Mark=year(claim_date)=year-1 and 10<=month(claim_date)<=12
or
year(claim_date)=year+1 and 1<=month(claim_date)<=3
or
year= year(claim_date);
run;
Would this work:
data want;
set have;
where mdy(10,1,year-1) <= CLAIM_DATE and mdy(3,31,year+1) >= CLAIM_DATE;
run;
DATA HAVE;
format PAT_ID 1. CLAIM_DATE date9. YEAR 4. ;
informat CLAIM_DATE date9. YEAR 4. MARK 1.;
input PAT_ID CLAIM_DATE YEAR MARK;
drop mark;
CARDS;
1 27-Dec-08 2011 0
1 19-Dec-09 2011 0
1 1-Jun-10 2011 0
1 1-Oct-10 2011 1
1 15-Nov-10 2011 1
1 1-Aug-11 2011 1
1 3-Jan-12 2011 1
1 5-Jan-12 2011 1
1 29-Dec-12 2011 0
2 2-May-14 2014 1
2 15-Oct-14 2014 1
2 13-Jan-15 2014 1
2 1-Feb-15 2014 1
2 18-Mar-15 2014 1
2 30-Sep-15 2014 0
2 1-Oct-15 2014 0
3 27-Dec-08 2011 0
3 15-Dec-09 2011 0
3 1-Jun-10 2011 0
3 1-Oct-10 2011 1
3 15-Nov-10 2011 1
3 1-Aug-11 2011 1
3 3-Jan-12 2011 1
3 2-Apr-12 2011 0
3 23-Nov-15 2011 0
3 5-Oct-16 2011 0
;
data want;
set have;
by pat_id;
Mark=year(claim_date)=year-1 and 10<=month(claim_date)<=12
or
year(claim_date)=year+1 and 1<=month(claim_date)<=3
or
year= year(claim_date);
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.