Help using Base SAS procedures

Help with data

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 127
Accepted Solution

Help with data

I have the following data.   I want Therapy for each Patient based on days_btw_refill.   If the days_btw_refill is greater than 60 days then I want the Therapy to change from 1 to 2 and so on

data have;

  input id  days_btw_refill;

cards;

1  31

1  30

1  38

1  70

1  35

1  45

1  32

1  53

1  26

1  82

1  36

2  28

2  38

I want the following Output for Therapies

id    days_btw_refill      Therapy

1        31                   1

1        30                   1

1        38                   1

1        70                   2

1        35                   2

1        45                   2

1        32                   2

1        53                   2

1        26                   2

1        82                   3

1        36                   3

2        28                   1

2        38                   1


Accepted Solutions
Solution
‎04-17-2015 12:20 PM
Super User
Posts: 11,343

Re: Help with data

Assuming the data is actually sorted by ID.

data want;

   set have;

   by id; /* if grouped by id but not in sort order add NOTSORTED*/

   retain Therapy .;

   if first.id then therapy=1;

   if days_btw_refill>60 then therapy + 1;

run;

View solution in original post


All Replies
Solution
‎04-17-2015 12:20 PM
Super User
Posts: 11,343

Re: Help with data

Assuming the data is actually sorted by ID.

data want;

   set have;

   by id; /* if grouped by id but not in sort order add NOTSORTED*/

   retain Therapy .;

   if first.id then therapy=1;

   if days_btw_refill>60 then therapy + 1;

run;

Respected Advisor
Posts: 3,156

Re: Help with data

Same concept as 's solution,

data want;

     set have;

     by id;

     if first.id then

           therapy=1;

     therapy+days_btw_refill>60;

run;

🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 198 views
  • 3 likes
  • 3 in conversation