Hi all,
I have data at the person-event level--that is, each row represents one event for one person. The data include ID number, a fixed date at the person level (ie, each time an ID recurs, this date will be the same), an event type variable, and an event date variable. IDs can recur.
ID Fixed date Event type Event date
1 5/4/2013 A 10/12/2012
1 5/4/2013 B 6/7/2013
1 5/4/2013 A 1/1/2013
2 9/2/2012 B 10/4/2012
2 9/2/2012 B 11/1/2012
3 10/4/2014 A 3/4/2013
What I want to be able to evaluate is whether a specific type of event occurred within 6 months of the fixed date (that is, whether the event date is within 6 months of the fixed date).
Any help is much appreciated.
I think its as simple as using intck function.
Intnx would be easier no?
data have;
id=1; fixed_date='05APR2013'd; event_type="A"; Event_date='10DEC2012'd; output;
id=1; fixed_date='05APR2013'd; event_type="A"; Event_date='06JUL2013'd; output;
run;
data want;
set have;
if fixed_date <= event_date <= intnx('month',fixed_date,6) then flag="Y";
run;
Six of one...half a dozen of the other.
Hi,
I tried this solution (intnx), and it seemed to work. While QCing, I checked a sample date (August 23, 2013) and tested to see what the program would return as the date 6 months after. It returned February 1st, 2014, which is 162 days later. Considering this, I'm confused about how it's calculating the time period of 6 months.
There are other options in the intnx function: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212700.htm
May need to put intnx('month',fixed_date,6,'same')
6 months: Is this by calendar date or number of days (=180)?
If it's calendar date then code as below should do.
data sample;
input ID:$5. Fixed_date:mmddyy10. Event_type:$5. Event_date:mmddyy10.;
format Fixed_date Event_date date9.;
within6month_flg=0;
select;
when (Fixed_date<=Event_date)
do;
if Fixed_date>intnx('month',Event_date,-6,'s') then within6month_flg=1;
end;
when (Fixed_date>Event_date)
do;
if Fixed_date<intnx('month',Event_date,6,'s') then within6month_flg=1;
end;
end;
datalines;
1 5/4/2013 A 10/12/2012
1 5/4/2013 B 6/7/2013
1 5/4/2013 A 1/1/2013
2 9/2/2012 B 10/4/2012
2 9/2/2012 B 11/1/2012
3 10/4/2014 A 3/4/2013
;
run;
No confusion necessary! Intck is simply checking # of boundaries crossed.
There are more than 180*2 days in a year. Using months and same is simply counting (given, say, startdate is 05jan2014 and end date is 04mar2014) how many month boundaries are crossed between the two (with the day indicating the boundary is the 5th of the month.
Please try
data have(where=(0 <= dur2 <= -6));
input ID$ Fixed_date :mmddyy10. Event_type $ Event_date :mmddyy10. ;
dur2= intck('month',Fixed_date,Event_date) ;
format Fixed_date Event_date date9. ;
cards;
1 5/4/2013 A 10/12/2012
1 5/4/2013 B 6/7/2013
1 5/4/2013 A 1/1/2013
2 9/2/2012 B 10/4/2012
2 9/2/2012 B 11/1/2012
3 10/4/2014 A 3/4/2013
;
run;
Thanks,
Jag
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.