Medicaition Sequence Question

Solved
Occasional Contributor
Posts: 7

Medicaition Sequence Question

Dear All,

Please let me know if there is a way to determine prescription sequences. Particularly I am interested in categorizing the patients based on the order in which they took medication for

group 1: AB

group 2: ABC

group 3: ABAC

A = medication 1

B = medication 2

C = medication 3

My data looks like this

patid    claim_date     medication

1          dec                    1

1          jan                     2

1          jan                     3

1          xxx                    1

2          xxx                    1

2          xxx                    1

2          xxx                    1

2          xxx                    1

2          xxx                    2

2          xxx                    1

2          xxx                    1

2          xxx                    3

3          xxx                    2

3          xxx                    1

3          xxx                    4

I was able to assign them to groups based on the date information and medication category information. However, when if used grouping, or any other technique that I know it is giving me just the first sequence for eg (ABC) when actually the patient took ABA and then C.

The output should be as follows:

patid     group

1           ABC

2           ACABA

3           BAC....

Please let me know if there is a way to assign them to groups or recode to get the desired answer. Please let me know if you need further information.

Sincerely,

Rakesh

Accepted Solutions
Solution
‎06-06-2014 06:39 PM
Super User
Posts: 8,075

Re: Medicaition Sequence Question

Use FIRST. processing to collapse the groups.  Just make sure to use the NOTSORTED option since the data is sorted by DATE and not my MEDICATION.

data have ;

input patid \$ claim_date \$ medication \$ @@ ;

cards;

1 dec A 1 jan B 1 jan C 1 xxx A

2 xxx A 2 xxx A 2 xxx A 2 xxx A 2 xxx B 2 xxx A 2 xxx A 2 xxx C

3 xxx B 3 xxx A 3 xxx D

run;

data want ;

do until (last.patid);

length trtgrp \$20 ;

set have ;

by patid medication notsorted ;

if first.medication then trtgrp = cats(trtgrp,medication);

end;

keep patid trtgrp ;

put patid= trtgrp=;

run;

patid=1 trtgrp=ABCA

patid=2 trtgrp=ABAC

All Replies
Super User
Posts: 13,508

Re: Medicaition Sequence Question

I think you'll get a better response if you provide a few more lines of input data AND and example of the desired output. You are using a description of AB, ABC or ABAC but not defining it.

Occasional Contributor
Posts: 7

Re: Medicaition Sequence Question

Hello,

Sincerely,

Rakesh

Solution
‎06-06-2014 06:39 PM
Super User
Posts: 8,075

Re: Medicaition Sequence Question

Use FIRST. processing to collapse the groups.  Just make sure to use the NOTSORTED option since the data is sorted by DATE and not my MEDICATION.

data have ;

input patid \$ claim_date \$ medication \$ @@ ;

cards;

1 dec A 1 jan B 1 jan C 1 xxx A

2 xxx A 2 xxx A 2 xxx A 2 xxx A 2 xxx B 2 xxx A 2 xxx A 2 xxx C

3 xxx B 3 xxx A 3 xxx D

run;

data want ;

do until (last.patid);

length trtgrp \$20 ;

set have ;

by patid medication notsorted ;

if first.medication then trtgrp = cats(trtgrp,medication);

end;

keep patid trtgrp ;

put patid= trtgrp=;

run;

patid=1 trtgrp=ABCA

patid=2 trtgrp=ABAC

Occasional Contributor
Posts: 7

Re: Medicaition Sequence Question

Dear Tom,

Sincerely,

Rakesh

🔒 This topic is solved and locked.