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

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

3 REPLIES 3
heffo
Pyrite | Level 9

Would this work:

 

data want;
	set have;
 	where mdy(10,1,year-1) <= CLAIM_DATE and mdy(3,31,year+1) >= CLAIM_DATE;
run;
novinosrin
Tourmaline | Level 20

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;
Cruise
Ammonite | Level 13
Great! Thank you very much!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 3 replies
  • 1090 views
  • 2 likes
  • 3 in conversation