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

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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

2 REPLIES 2
ballardw
Super User

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;

Haikuo
Onyx | Level 15

Same concept as 's solution,

data want;

     set have;

     by id;

     if first.id then

           therapy=1;

     therapy+days_btw_refill>60;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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