DATA Step, Macro, Functions and more

Array to determine Primary Therapy

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

Array to determine Primary Therapy

Hello All,

I have a wide data set containing the information on 10 prescription drugs taken by patients(RX_1-RX_10). The data set contains the order in which the drugs were taken (order), the number of days on that particular prescription (days), and whether the patient was started on the drug within 72hrs of admission to the hospital(_72 0=Yes, 1=No).

I want to use this data to determine whether the drug was their primary therapy (Prime 0=Yes, 1=No).

To be considered a patients primary therapy they must have taken the therapy within 72hrs of admission and been on the therapy for greater than or equal to 10 days. Additionally, it must be the earliest taken therapy.

So if a patient took two different drugs within 72hrs of admission but took the first ordered drug for 1 day and the second ordered drug for 10 days then the primary therapy would be the second drug (See Small Example Data Set Below).

ID

RX1_order

RX2_order

RX1_days

RX2_days

RX1_72

RX2_72

RX1_Prime

RX2_prime

1

1

1

10

8

0

0

0

0

2

1

1

4

17

1

1

1

1

3

1

2

13

15

0

0

0

1

4

2

1

5

20

1

0

1

0

5

1

2

2

10

1

0

1

0

Thanks,

Jonathan


Accepted Solutions
Solution
‎07-27-2011 10:41 PM
PROC Star
Posts: 7,489

Re: Array to determine Primary Therapy

I'm still not sure if I understand.  However, if what you are trying to say is that if the best orders don't meet the other conditions, later orders can be used, then the following might accomplish what you want:

data have;

  input ID

RX1_order

RX2_order

RX1_days

RX2_days

RX1_72

RX2_72

;

cards;

1 1 1 10 8 0 0

2 1 1 4 17 1 1

3 1 2 13 15 0 0

4 2 1 5 20 1 0

5 1 2 2 10 1 0

;

%let numrx=2;

data want;

  set have;

  Array Order[&numrx.] RX_order_1-RX_order_&numrx.;

  Array Three[&numrx.] RX_72_1-RX_72_&numrx.;

  Array Day[&numrx.] RX_day_1-RX_day_&numrx.;

  array primary(&numrx.);

  DO i=1 to &numrx.;

    If Three=0 and Day GE 10 then do;

      if Order eq 1 then do;

        bestOrder=Order(i);

        primary=0;

      end;

      else if not missing(bestOrder) then do;

        if Order eq bestOrder then primary=0;

      end;

      else do;

        bestOrder=Order;

              primary=0;

      end;

    end;

  end;

run;

View solution in original post


All Replies
PROC Star
Posts: 7,489

Re: Array to determine Primary Therapy

For ID 1 why do you indicate that RX2 is a primary when the prescription was only for 8 days?  Also, for ID 5, then second drug was order=2.  According to your description, shouldn't it have had a primary value of 1 (i.e., no)?

Occasional Contributor
Posts: 11

Array to determine Primary Therapy

Art-

     ID 1 was a typo.  However, I should indicate that the order variable was created by ranking the start date of each therapy. If RX_1 and RX_2 had the same start date then both would have an order of 1. If the RX_2 was started after RX_1 then the value would be 2.

ID

RX1_order

RX2_order

RX1_days

RX2_days

RX1_72

RX2_72

RX1_Prime

RX2_prime

1

1

1

10

8

0

0

0

1

2

1

1

4

17

1

1

1

1

3

1

2

13

15

0

0

0

1

4

2

1

5

20

1

0

1

0

5

1

2

2

10

1

1

1

0

PROC Star
Posts: 7,489

Re: Array to determine Primary Therapy

If the answers to my questions are that they were miscoded, then you might be able to achieve what you want with something like:

%let numrx=10;

data want;

  set have;

  array allrx(3,&numrx.) RX1_order--RX&numrx._72;

  array primary(&numrx.);

  do i=1 to &numrx.;

    if allrx(1,i) eq 1 and allrx(2,i) ge 10 and

     allrx(3,i) eq 0 then primary(i)=0;

    else primary(i)=1;

  end;

run;

PROC Star
Posts: 7,489

Array to determine Primary Therapy

Then I'm confused.  If order is part of your required logic and an RX can only be primary if it has a value of 1, then RX2 cannot be a primary.  Am I missing something?

Occasional Contributor
Posts: 11

Re: Array to determine Primary Therapy

Data New;

      Set Old;

Array Order[10] RX_order_1-RX_order_10;

Array Three[10] RX_72_1-RX_72_10;

Array Day[10] RX_day_1-RX_day_10;

DO i=1 to 10;

If Three=0 and Day GE 10 then do;

The goal is use the order variable to determine the earliest therapy that meets the criteria

Example 1

Criteria  1:  Taken with 72 hours of admission

RX1_72=0

RX2_72=0

Criteria 2: Therapy taken for 10 days

RX1_days  > 10 days

RX2_days > 10 days

Both RX1 and RX2 meet criteria

Criteria 3: Earliest Taken Therapy

RX1_order=1 

RX2_order=1

RX1_order=RX2_order

Action: Both RX1 and RX2 are listed as the Primary Therapy

Example 2

Criteria  1:  Taken with 72 hours of admission

RX1_72=0

RX1_72=0

Criteria 2: Therapy taken for 10 days

RX1_days < 10 days

RX2_days>10 days

RX2_days  meets criteria

Criteria 3: Earliest Taken Therapy

RX2_order=2

Action:  RX2 is listed as Primary Therapy

Example

Criteria  1:  Taken with 72 hours of admission

RX1_72=0

RX1_72=0

Criteria 2: Therapy taken for 10 days

RX1_days >10 days

RX2_days < 10 days

RX1_days meets the criteria

Criteria 3: Earliest Taken Therapy

RX1_order=1   is the lowest ranked order

Action:  RX1 is listed as the Primary Therapy

Criteria  Three only matters because I have ten therapies whose order variable can rank from 1 to 10.

Solution
‎07-27-2011 10:41 PM
PROC Star
Posts: 7,489

Re: Array to determine Primary Therapy

I'm still not sure if I understand.  However, if what you are trying to say is that if the best orders don't meet the other conditions, later orders can be used, then the following might accomplish what you want:

data have;

  input ID

RX1_order

RX2_order

RX1_days

RX2_days

RX1_72

RX2_72

;

cards;

1 1 1 10 8 0 0

2 1 1 4 17 1 1

3 1 2 13 15 0 0

4 2 1 5 20 1 0

5 1 2 2 10 1 0

;

%let numrx=2;

data want;

  set have;

  Array Order[&numrx.] RX_order_1-RX_order_&numrx.;

  Array Three[&numrx.] RX_72_1-RX_72_&numrx.;

  Array Day[&numrx.] RX_day_1-RX_day_&numrx.;

  array primary(&numrx.);

  DO i=1 to &numrx.;

    If Three=0 and Day GE 10 then do;

      if Order eq 1 then do;

        bestOrder=Order(i);

        primary=0;

      end;

      else if not missing(bestOrder) then do;

        if Order eq bestOrder then primary=0;

      end;

      else do;

        bestOrder=Order;

              primary=0;

      end;

    end;

  end;

run;

Occasional Contributor
Posts: 11

Re: Array to determine Primary Therapy

Art-

Thanks once again for taking the time to help me with my SAS trouble.

Thanks

Jonathan

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 179 views
  • 0 likes
  • 2 in conversation