BookmarkSubscribeRSS Feed
Walternate
Obsidian | Level 7

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.

8 REPLIES 8
DBailey
Lapis Lazuli | Level 10

I think its as simple as using intck function.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

DBailey
Lapis Lazuli | Level 10

Six of one...half a dozen of the other.

Walternate
Obsidian | Level 7

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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')

Patrick
Opal | Level 21

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;

art297
Opal | Level 21

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.

Jagadishkatam
Amethyst | Level 16

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

Thanks,
Jag

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 3097 views
  • 0 likes
  • 6 in conversation