Drug discontinuation

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Drug discontinuation

prasad
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Drug discontinuation

Jignesh Sutar
Hi Prasad,

Try something like this, which picks out 2 consecutive "N"s. It may not be perfect as you many want to classify a "second discontinuation" as after re-continuing the drugs after X periods and then discontinuing it again for 2 periods...

But the code below shall give you a starting point.

output close all.
vector items= VAR00001  to VAR00006.
vector Y(6).
compute #run    = 0.
compute #max_run = 0.
loop #item_i = 1 to 5.
    do if (items(#item_i+1)="N" & items(#item_i)="N").
        compute  y(#item_i+1) = 1.
    end if.
end loop.
exe.


HTH,
Jignesh



On 4 December 2013 01:10, prasad <[hidden email]> wrote:
ID      V1_jan11        V2_feb11        V3_mar11        V4_apr11        V5_may11        V6_jun11        V7_jul11
1       Y                  N                    N          Y                     Y               N         N
2       Y                  Y                    Y          N                     N               Y         Y
3       Y                  Y                    N          N                     Y               Y         Y
4       Y                  Y                    N          N                     Y               N         N

I have categorical variables defined: ‘Y’ =taking drug and ‘N’ =not taking
drug
I have defined drug discontinuation as count of 2 consecutive ‘N’
I would like to identify the appearance of first 2 consecutive Ns for each
case as ‘first’ discontinuation, second 2 consecutive Ns as ‘second’
discontinuation and so on…
Any help will be appreciated

thanks
prasad



--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Drug-discontinuation-tp5723410.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: Drug discontinuation

Bruce Weaver
Administrator
In reply to this post by prasad
How about something like this?  The NN variables flag the start of strings of 2 or more Ns.

NEW FILE.
DATASET CLOSE all.

DATA LIST list /  ID (f1) V1 to V7 (7A1).
BEGIN DATA
1 Y N N Y Y N N
2 Y Y Y N N Y Y
3 Y Y N N Y Y Y
4 Y Y N N Y N N
5 N N N N Y N N
6 Y Y N Y Y Y N
END DATA.


STRING #AllYN (A8).
RECODE V1 V2 ("Y" = "y").
COMPUTE #AllYN = CONCAT(V1 to V7,"Y").
RECODE V1 V2 ("y" = "Y").
DO REPEAT NN = NN1 to NN3.
- COMPUTE #Flag = CHAR.INDEX(#AllYN,"NNY").
- DO IF #Flag GT 0.
-   COMPUTE NN = CHAR.INDEX(#AllYN,"NN").
-   LOOP # = NN to #Flag + 1.
-     COMPUTE SUBSTR(#AllYN,#,1) = "n".
-   END LOOP.
- END IF.
END REPEAT.
RECODE NN1 to NN3(sysmis=0).
FORMATS NN1 to NN3(f1).
LIST.

Output:
ID V1 V2 V3 V4 V5 V6 V7 NN1 NN2 NN3 
 
 1 Y  N  N  Y  Y  N  N   2   6   0 
 2 Y  Y  Y  N  N  Y  Y   4   0   0 
 3 Y  Y  N  N  Y  Y  Y   3   0   0 
 4 Y  Y  N  N  Y  N  N   3   6   0 
 5 N  N  N  N  Y  N  N   1   6   0 
 6 Y  Y  N  Y  Y  Y  N   0   0   0 
 
Number of cases read:  6    Number of cases listed:  6


prasad wrote
ID V1_jan11 V2_feb11 V3_mar11 V4_apr11 V5_may11 V6_jun11 V7_jul11
1 Y           N                 N   Y                 Y         N   N
2 Y           Y                Y   N                 N         Y   Y
3 Y           Y                N   N                 Y         Y   Y
4 Y           Y                N   N                 Y         N   N

I have categorical variables defined: ‘Y’ =taking drug and ‘N’ =not taking drug
I have defined drug discontinuation as count of 2 consecutive ‘N’
I would like to identify the appearance of first 2 consecutive Ns for each case as ‘first’ discontinuation, second 2 consecutive Ns as ‘second’ discontinuation and so on…
Any help will be appreciated

thanks
prasad
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Drug discontinuation

Maguin, Eugene
Hi Bruce, where's  the code? Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bruce Weaver
Sent: Wednesday, December 04, 2013 10:01 AM
To: [hidden email]
Subject: Re: Drug discontinuation

How about something like this?  The NN variables flag the start of strings of
2 or more Ns.





prasad wrote

> ID    V1_jan11        V2_feb11        V3_mar11        V4_apr11        V5_may11        V6_jun11        V7_jul11
> 1     Y                  N                    N          Y                     Y               N
> N
> 2     Y                  Y                    Y          N                     N               Y         Y
> 3     Y                  Y                    N          N                     Y               Y         Y
> 4     Y                  Y                    N          N                     Y               N         N
>
> I have categorical variables defined: ‘Y’ =taking drug and ‘N’ =not
> taking drug I have defined drug discontinuation as count of 2
> consecutive ‘N’
> I would like to identify the appearance of first 2 consecutive Ns for
> each case as ‘first’ discontinuation, second 2 consecutive Ns as ‘second’
> discontinuation and so on…
> Any help will be appreciated
>
> thanks
> prasad





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Drug-discontinuation-tp5723410p5723416.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Drug discontinuation

Bruce Weaver
Administrator
I had to go look at the UGA archive to understand your question, Gene, because I can see the code (and output) in the Nabble archive.  You can view it here:

http://spssx-discussion.1045642.n5.nabble.com/Drug-discontinuation-tp5723410p5723416.html

I used the Raw Text option when posting via Nabble.  Perhaps that made it invisible in e-mail and the UGA archives?  Funny though, because I've used Raw Text before, and think it worked just fine.  

Cheers,
Bruce


Maguin, Eugene wrote
Hi Bruce, where's  the code? Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bruce Weaver
Sent: Wednesday, December 04, 2013 10:01 AM
To: [hidden email]
Subject: Re: Drug discontinuation

How about something like this?  The NN variables flag the start of strings of
2 or more Ns.





prasad wrote
> ID    V1_jan11        V2_feb11        V3_mar11        V4_apr11        V5_may11        V6_jun11        V7_jul11
> 1     Y                  N                    N          Y                     Y               N
> N
> 2     Y                  Y                    Y          N                     N               Y         Y
> 3     Y                  Y                    N          N                     Y               Y         Y
> 4     Y                  Y                    N          N                     Y               N         N
>
> I have categorical variables defined: ‘Y’ =taking drug and ‘N’ =not
> taking drug I have defined drug discontinuation as count of 2
> consecutive ‘N’
> I would like to identify the appearance of first 2 consecutive Ns for
> each case as ‘first’ discontinuation, second 2 consecutive Ns as ‘second’
> discontinuation and so on…
> Any help will be appreciated
>
> thanks
> prasad





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Drug-discontinuation-tp5723410p5723416.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Drug discontinuation

Rich Ulrich
In reply to this post by Bruce Weaver
Here's something I haven't seen before.  I do find
Bruce's proposed lines of code at Nabble, even though (like Gene)
I don't see it at my regular feed from the List.

My first thought was that live.com might be deleting the HTML code -
but it never has before.  Neither has the list.

Below - Here are Bruce's lines.  That is similar to what I thought of,
with small differences.  I would use the index function to find "YNN"
and add 1 to the reported location.  Then, zap Y to y, and search again
until index reports 0.  That could fit the syntax of LOOP instead of
DO REPEAT.

== Bruce's code, without some formatting that forces things to line up right.

NEW FILE.
DATASET CLOSE all.
DATA LIST list /  ID (f1) V1 to V7 (7A1).
BEGIN DATA.
1 Y N N Y Y N N
2 Y Y Y N N Y Y
3 Y Y N N Y Y Y
4 Y Y N N Y N N
5 N N N N Y N N
6 Y Y N Y Y Y N
END DATA.
STRING #AllYN (A8).
RECODE V1 V2 ("Y" = "y").
COMPUTE #AllYN = CONCAT(V1 to V7,"Y").
RECODE V1 V2 ("y" = "Y").
DO REPEAT NN = NN1 to NN3.
- COMPUTE #Flag = CHAR.INDEX(#AllYN,"NNY").
- DO IF #Flag GT 0.
-   COMPUTE NN = CHAR.INDEX(#AllYN,"NN").
-   LOOP # = NN to #Flag + 1.
-     COMPUTE SUBSTR(#AllYN,#,1) = "n".
-   END LOOP.
- END IF.
END REPEAT.
RECODE NN1 to NN3(sysmis=0).
FORMATS NN1 to NN3(f1).
LIST.
Output:ID V1 V2 V3 V4 V5 V6 V7 NN1 NN2 NN3
    1 Y  N  N  Y  Y  N  N   2   6   0
 2 Y  Y  Y  N  N  Y  Y   4   0   0
    3 Y  Y  N  N  Y  Y  Y   3   0   0
    4 Y  Y  N  N  Y  N  N   3   6   0
    5 N  N  N  N  Y  N  N   1   6   0
 6 Y  Y  N  Y  Y  Y  N   0   0   0
Number of cases read:  6    Number of cases listed:  6

--
Rich Ulrich

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Drug discontinuation

Bruce Weaver
Administrator
In reply to this post by Bruce Weaver
Here it is again (without the Raw Text option) with some comments inserted.

NEW FILE.
DATASET CLOSE all.

DATA LIST list /  ID (f1) V1 to V7 (7A1).
BEGIN DATA
1 Y N N Y Y N N
2 Y Y Y N N Y Y
3 Y Y N N Y Y Y
4 Y Y N N Y N N
5 N N N N Y N N
6 N N Y N N Y N
7 Y N N Y N N Y
8 Y Y N Y Y Y N
END DATA.

* Combine all the Y-N codes into a single string variable
* with an extra Y tacked onto the end.  This will allow me to
* search for occurrences of "NNY".  Before combining all of the
* codes, recode Y to y in the first two variables, as neither
* of those can be preceded by two Ns.

STRING #AllYN (A8).
RECODE V1 V2 ("Y" = "y").
COMPUTE #AllYN = CONCAT(V1 to V7,"Y").

* Restore V1 and V2 to their original state.
RECODE V1 V2 ("y" = "Y").

DO REPEAT NN = NN1 to NN3.
* Find first "NNY" string.
- COMPUTE #Flag = CHAR.INDEX(#AllYN,"NNY").
- DO IF #Flag GT 0.
*   Find position of the first "NN".
-   COMPUTE NN = CHAR.INDEX(#AllYN,"NN").
*   Replace "N" with "n" up to the point of the first "NNY" string.
-   LOOP # = NN to #Flag + 1.
-     COMPUTE SUBSTR(#AllYN,#,1) = "n".
-   END LOOP.
- END IF.
END REPEAT.
RECODE NN1 to NN3(sysmis=0).
FORMATS NN1 to NN3(f1).
LIST.

OUTPUT:

ID V1 V2 V3 V4 V5 V6 V7 NN1 NN2 NN3
 
 1 Y  N  N  Y  Y  N  N   2   6   0
 2 Y  Y  Y  N  N  Y  Y   4   0   0
 3 Y  Y  N  N  Y  Y  Y   3   0   0
 4 Y  Y  N  N  Y  N  N   3   6   0
 5 N  N  N  N  Y  N  N   1   6   0
 6 N  N  Y  N  N  Y  N   1   4   0
 7 Y  N  N  Y  N  N  Y   2   5   0
 8 Y  Y  N  Y  Y  Y  N   0   0   0
 
Number of cases read:  8    Number of cases listed:  8

Bruce Weaver wrote
I had to go look at the UGA archive to understand your question, Gene, because I can see the code (and output) in the Nabble archive.  You can view it here:

http://spssx-discussion.1045642.n5.nabble.com/Drug-discontinuation-tp5723410p5723416.html

I used the Raw Text option when posting via Nabble.  Perhaps that made it invisible in e-mail and the UGA archives?  Funny though, because I've used Raw Text before, and think it worked just fine.  

Cheers,
Bruce


Maguin, Eugene wrote
Hi Bruce, where's  the code? Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bruce Weaver
Sent: Wednesday, December 04, 2013 10:01 AM
To: [hidden email]
Subject: Re: Drug discontinuation

How about something like this?  The NN variables flag the start of strings of
2 or more Ns.





prasad wrote
> ID    V1_jan11        V2_feb11        V3_mar11        V4_apr11        V5_may11        V6_jun11        V7_jul11
> 1     Y                  N                    N          Y                     Y               N
> N
> 2     Y                  Y                    Y          N                     N               Y         Y
> 3     Y                  Y                    N          N                     Y               Y         Y
> 4     Y                  Y                    N          N                     Y               N         N
>
> I have categorical variables defined: ‘Y’ =taking drug and ‘N’ =not
> taking drug I have defined drug discontinuation as count of 2
> consecutive ‘N’
> I would like to identify the appearance of first 2 consecutive Ns for
> each case as ‘first’ discontinuation, second 2 consecutive Ns as ‘second’
> discontinuation and so on…
> Any help will be appreciated
>
> thanks
> prasad





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Drug-discontinuation-tp5723410p5723416.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Drug discontinuation

Bruce Weaver
Administrator
In reply to this post by Rich Ulrich
Here is Rich's variation on the earlier theme.  I think it's a bit tidier than what I posted earlier--e.g., the ability to exit the LOOP early when there are no YNN strings.


DATA LIST list /  ID (f1) V1 to V7 (7A1).
BEGIN DATA
1 Y N N Y Y N N
2 Y Y Y N N Y Y
3 Y Y N N Y Y Y
4 Y Y N N Y N N
5 N N N N Y N N
6 N N Y N N Y N
7 Y N N Y N N Y
8 Y Y N Y Y Y N
END DATA.

* Combine all the Y-N codes into a single string variable
* with an extra Y tacked onto the front end.  This will allow me to
* search for occurrences of "YNN".  

STRING #AllYN (A8).
COMPUTE #AllYN = CONCAT("Y",V1 to V7).

* Rich said:
* "I would use the index function to find "YNN"
   and add 1 to the reported location.  Then, zap Y to y, and search again
   until index reports 0.  That could fit the syntax of LOOP instead of
   DO REPEAT."

VECTOR NN(3).
LOOP # = 1 to 3.
COMPUTE #YNN = CHAR.INDEX(#AllYN,"YNN").
DO IF #YNN GT 0.
- COMPUTE NN(#) = #YNN.
- COMPUTE SUBSTR(#AllYN,#YNN,1) = "y".
END IF.
END LOOP if (#YNN EQ 0).
FORMATS NN1 to NN3(F1).
RECODE NN1 to NN3 (SYSMIS=0).
LIST.

Output:

ID V1 V2 V3 V4 V5 V6 V7 NN1 NN2 NN3
 
 1 Y  N  N  Y  Y  N  N   2   6   0
 2 Y  Y  Y  N  N  Y  Y   4   0   0
 3 Y  Y  N  N  Y  Y  Y   3   0   0
 4 Y  Y  N  N  Y  N  N   3   6   0
 5 N  N  N  N  Y  N  N   1   6   0
 6 N  N  Y  N  N  Y  N   1   4   0
 7 Y  N  N  Y  N  N  Y   2   5   0
 8 Y  Y  N  Y  Y  Y  N   0   0   0
 
Number of cases read:  8    Number of cases listed:  8


Rich Ulrich wrote
Here's something I haven't seen before.  I do find
Bruce's proposed lines of code at Nabble, even though (like Gene)
I don't see it at my regular feed from the List.

My first thought was that live.com might be deleting the HTML code -
but it never has before.  Neither has the list.

Below - Here are Bruce's lines.  That is similar to what I thought of,
with small differences.  I would use the index function to find "YNN"
and add 1 to the reported location.  Then, zap Y to y, and search again
until index reports 0.  That could fit the syntax of LOOP instead of
DO REPEAT.

== Bruce's code, without some formatting that forces things to line up right.

NEW FILE.
DATASET CLOSE all.
DATA LIST list /  ID (f1) V1 to V7 (7A1).
BEGIN DATA.
1 Y N N Y Y N N
2 Y Y Y N N Y Y
3 Y Y N N Y Y Y
4 Y Y N N Y N N
5 N N N N Y N N
6 Y Y N Y Y Y N
END DATA.
STRING #AllYN (A8).
RECODE V1 V2 ("Y" = "y").
COMPUTE #AllYN = CONCAT(V1 to V7,"Y").
RECODE V1 V2 ("y" = "Y").
DO REPEAT NN = NN1 to NN3.
- COMPUTE #Flag = CHAR.INDEX(#AllYN,"NNY").
- DO IF #Flag GT 0.
-   COMPUTE NN = CHAR.INDEX(#AllYN,"NN").
-   LOOP # = NN to #Flag + 1.
-     COMPUTE SUBSTR(#AllYN,#,1) = "n".
-   END LOOP.
- END IF.
END REPEAT.
RECODE NN1 to NN3(sysmis=0).
FORMATS NN1 to NN3(f1).
LIST.
Output:ID V1 V2 V3 V4 V5 V6 V7 NN1 NN2 NN3
    1 Y  N  N  Y  Y  N  N   2   6   0
 2 Y  Y  Y  N  N  Y  Y   4   0   0
    3 Y  Y  N  N  Y  Y  Y   3   0   0
    4 Y  Y  N  N  Y  N  N   3   6   0
    5 N  N  N  N  Y  N  N   1   6   0
 6 Y  Y  N  Y  Y  Y  N   0   0   0
Number of cases read:  6    Number of cases listed:  6

--
Rich Ulrich

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).