Find the first, second, third... drug chosen

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

Find the first, second, third... drug chosen

mils
Hi Everyone,

I have patients' data regarding their regime behavior across time. Below you can find a small example of my data (they are string variables).


Current               Previous            Before that-1    Before that-2     Before that-3 . . . . . . . .Before that-6
     drug a             drug b                drug c              drug d                  .
     drug b             drug c                drug z               .                     drug m
     drug c              .                       drug b               drug c                  .
     drug d             drug a                drug z               drug r                  .
     drug f              drug a                drug z               other drug            .
     drug f              drug a                Other drug         drug b                  .

And I want to find out which drugs did patients take first, second, third.... (sixth)

First                 Second              Third            Fourth . . . . . . . . . . Sixth

drug d                  drug c           drug b          drug a          
drug m                 drug z           drug c          drug b      
drug c                  drug b           drug c             .
drug r                  drug z            drug a          drug d    
drug z                  drug a           drug f             .
drug b                  drug a           drug f


The main problem I'm facing are those how didn't answer (.) and those who answer "other drug" which should not be taken into account when finding out which drugs did they take first, second, third....

Any help will be really appreciate it.

Thanks in advance.
mils
Reply | Threaded
Open this post in threaded view
|

Re: Find the first, second, third... drug chosen

David Marso
Administrator
VARSTOCASES...
SORT...
SELECT...
CASESTOVARS...

Or a bunch of messy LOOPS and VECTORS...
------------------
mils wrote
Hi Everyone,

I have patients' data regarding their regime behavior across time. Below you can find a small example of my data (they are string variables).


Current               Previous            Before that-1    Before that-2     Before that-3 . . . . . . . .Before that-6
     drug a             drug b                drug c              drug d                  .
     drug b             drug c                drug z               .                     drug m
     drug c              .                       drug b               drug c                  .
     drug d             drug a                drug z               drug r                  .
     drug f              drug a                drug z               other drug            .
     drug f              drug a                Other drug         drug b                  .

And I want to find out which drugs did patients take first, second, third.... (sixth)

First                 Second              Third            Fourth . . . . . . . . . . Sixth

drug d                  drug c           drug b          drug a          
drug m                 drug z           drug c          drug b      
drug c                  drug b           drug c             .
drug r                  drug z            drug a          drug d    
drug z                  drug a           drug f             .
drug b                  drug a           drug f


The main problem I'm facing are those how didn't answer (.) and those who answer "other drug" which should not be taken into account when finding out which drugs did they take first, second, third....

Any help will be really appreciate it.

Thanks in advance.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Automatic reply: Find the first, second, third... drug chosen

Genevieve Odoom
Thank you for your email. Please note that I am on vacation beginning Thursday, April 11th till Monday April 15th with limited access to emails. I will respond to your email upon my return to the office on Monday April 15, 2013.

Should you need immediate assistance please contact Dan Buchanan at ext. 229 ([hidden email]<mailto:[hidden email]>) .

Thank you.

Genevieve Odoom
Policy and Program Analyst
OANHSS
7050 Weston Rd.
Suite 700
Woodbridge, On
L4L 8G7
Tel: (905) 851-8821 x241 Fax: (905) 851-0744
[hidden email]
www.oanhss.org

=====================
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: Find the first, second, third... drug chosen

Art Kendall
In reply to this post by mils
Open a new instance of SPSS. Paste the syntax below into s syntax window and run it.
Does this look like what you are trying to do?

You would need to adapt it according to whether you have long strings as the variables, in which case you would most likely start with AUTORECODE with /GROUP. that would give you numbers.  "theset" might have to be wide enough for 6 2 digit numbers, etc.




* cases and single letter  items.

new file.
input program.
   vector drug (6,a1).
   loop id = 1 to 25.
      loop #p = 1 to 6.
         compute drug(#p) =string(RND(RV.UNIFORM(64.5,90.5)),PIB).
      end loop.
      end case.
   end loop.
   end file.
end input program.
*reverse the order.
match files file=*
 /rename(drug6 drug5 drug4 drug3 drug2 drug1=
         first second third fourth fifth sixth)
 /keep = id first second third fourth fifth  sixth.
list.
*shrink the set of events  removing drugs names ge "T".
string theset(a6).
do repeat event = first to sixth.
if event lt "T" theset= concat(rtrim(theset),event).
end repeat.
*expand the set of events.
do repeat event = first to sixth/ index= 1 to 6.
compute event = substr(theset,index,1).
end repeat.
list.



 

Art Kendall
Social Research Consultants
On 4/11/2013 7:59 AM, mils [via SPSSX Discussion] wrote:
Hi Everyone,

I have patients' data regarding their regime behavior across time. Below you can find a small example of my data (they are string variables).


Current               Previous            Before that-1    Before that-2     Before that-3 . . . . . . . .Before that-6
     drug a             drug b                drug c              drug d                  .
     drug b             drug c                drug z               .                     drug m
     drug c              .                       drug b               drug c                  .
     drug d             drug a                drug z               drug r                  .
     drug f              drug a                drug z               other drug            .
     drug f              drug a                Other drug         drug b                  .

And I want to find out which drugs did patients take first, second, third.... (sixth)

First                 Second              Third            Fourth . . . . . . . . . . Sixth

drug d                  drug c           drug b          drug a          
drug m                 drug z           drug c          drug b      
drug c                  drug b           drug c             .
drug r                  drug z            drug a          drug d    
drug z                  drug a           drug f             .
drug b                  drug a           drug f


The main problem I'm facing are those how didn't answer (.) and those who answer "other drug" which should not be taken into account when finding out which drugs did they take first, second, third....

Any help will be really appreciate it.

Thanks in advance.
mils



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Find-the-first-second-third-drug-chosen-tp5719400.html
To start a new topic under SPSSX Discussion, email [hidden email]
To unsubscribe from SPSSX Discussion, click here.
NAML

Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Find the first, second, third... drug chosen

David Marso
Administrator
Another example of VECTOR LOOP vs DO REPEAT.
LOOP allows backwards traversal which is useful here.
-------------------------------------------------------------
MATRIX.
SAVE (TRUNC(UNIFORM(25,6)*25)+65) / OUTFILE * / VARIABLES drug01 TO drug06.
END MATRIX.

VECTOR X=Drug01 TO Drug06 /S(6,A1).
COMPUTE #=1.
STRING #S(A1).
LOOP ##=6 TO 1 BY -1.
+  COMPUTE #S=STRING(X(##),PIB2).
+  DO IF #S NE "X".
+    COMPUTE S(#)=#S.
+    COMPUTE #=#+1.
+  END IF.
END LOOP.
LIST.




drug01 drug02 drug03 drug04 drug05 drug06 S1 S2 S3 S4 S5 S6

66.000 86.000 78.000 70.000 87.000 71.000 G  W  F  N  V  B
86.000 68.000 76.000 78.000 67.000 69.000 E  C  N  L  D  V
77.000 70.000 87.000 72.000 85.000 80.000 P  U  H  W  F  M
70.000 85.000 68.000 82.000 66.000 82.000 R  B  R  D  U  F
80.000 85.000 77.000 75.000 69.000 79.000 O  E  K  M  U  P
72.000 77.000 70.000 86.000 87.000 66.000 B  W  V  F  M  H
73.000 76.000 73.000 83.000 70.000 82.000 R  F  S  I  L  I
78.000 67.000 71.000 87.000 78.000 83.000 S  N  W  G  C  N
84.000 66.000 87.000 88.000 71.000 76.000 L  G  W  B  T
75.000 66.000 80.000 72.000 78.000 68.000 D  N  H  P  B  K
79.000 72.000 72.000 82.000 85.000 78.000 N  U  R  H  H  O
71.000 69.000 81.000 68.000 80.000 76.000 L  P  D  Q  E  G
86.000 88.000 87.000 79.000 76.000 87.000 W  L  O  W  V
89.000 85.000 75.000 85.000 76.000 82.000 R  L  U  K  U  Y
82.000 65.000 77.000 72.000 65.000 81.000 Q  A  H  M  A  R
80.000 88.000 77.000 79.000 86.000 84.000 T  V  O  M  P
73.000 75.000 67.000 85.000 74.000 74.000 J  J  U  C  K  I
74.000 86.000 68.000 85.000 67.000 68.000 D  C  U  D  V  J
81.000 66.000 85.000 66.000 73.000 86.000 V  I  B  U  B  Q
70.000 77.000 87.000 85.000 75.000 73.000 I  K  U  W  M  F
65.000 67.000 80.000 83.000 86.000 69.000 E  V  S  P  C  A
74.000 69.000 65.000 84.000 69.000 71.000 G  E  T  A  E  J
86.000 86.000 77.000 82.000 88.000 68.000 D  R  M  V  V
74.000 82.000 80.000 76.000 73.000 78.000 N  I  L  P  R  J
80.000 78.000 75.000 65.000 85.000 71.000 G  U  A  K  N  P


Number of cases read:  25    Number of cases listed:  25


Alternatively, cut all the crap and just go jugular.
VARSTOCASES /ID=ID/MAKE S FROM DRUG01 TO drug06 / INDEX=Ind.
SORT CASES BY ID (A) Ind (D).
DELETE VARIABLES Ind.
SELECT IF (....).
CASESTOVARS ID=ID.

Art Kendall wrote
Open a
          new instance of SPSS. Paste the
            syntax below into s syntax window and run it.
            Does this look like what you are trying to
              do?
             
              You would need to adapt it according to
                whether you have long strings as the variables, in which
                case you would most likely start with
                  AUTORECODE with /GROUP. that would give you numbers.  "theset" might have to
                              be wide enough for 6 2 digit numbers, etc.
                   
                 
         
         
          * cases and single letter  items.
        new file.
        input program.
           vector drug (6,a1).
           loop id = 1 to 25.
              loop #p = 1 to 6.
                 compute drug(#p)
          =string(RND(RV.UNIFORM(64.5,90.5)),PIB).
              end loop.
              end case.
           end loop.
           end file.
        end input program.
        *reverse the order.
        match files file=*
         /rename(drug6 drug5 drug4 drug3 drug2 drug1=
                 first second third fourth fifth sixth)
         /keep = id first second third fourth fifth  sixth.
        list.
        *shrink the set of events  removing drugs names ge "T".
        string theset(a6).
        do repeat event = first to sixth.
        if event lt "T" theset= concat(rtrim(theset),event).
        end repeat.
        *expand the set of events.
        do repeat event = first to sixth/ index= 1 to 6.
        compute event = substr(theset,index,1).
        end repeat.
        list.
       
       
         
      Art Kendall
Social Research Consultants
      On 4/11/2013 7:59 AM, mils [via SPSSX Discussion] wrote:
   
     Hi Everyone,
     
     
      I have patients' data regarding their regime behavior across time.
      Below you can find a small example of my data (they are string
      variables).
     
     
     
      Current               Previous            Before that-1    Before
      that-2     Before that-3 . . . . . . . .Before that-6
     
           drug a             drug b                drug c            
       drug d                  .
     
           drug b             drug c                drug z              
      .                     drug m
     
           drug c              .                       drug b          
          drug c                  .
     
           drug d             drug a                drug z              
      drug r                  .
     
           drug f              drug a                drug z            
        other drug            .
     
           drug f              drug a                Other drug        
      drug b                  .
     
     
      And I want to find out which drugs did patients take first,
      second, third.... (sixth)
     
     
      First                 Second              Third            Fourth
      . . . . . . . . . . Sixth
     
     
      drug d                  drug c           drug b          drug a  
             
      drug m                 drug z           drug c          drug b    
       
     
      drug c                  drug b           drug c             .
     
      drug r                  drug z            drug a          drug d  
       
     
      drug z                  drug a           drug f             .
      drug b                  drug a           drug f
     
     
      The main problem I'm facing are those how didn't answer (.) and
      those who answer "other drug" which should not be taken into
      account when finding out which drugs did they take first, second,
      third....
     
     
      Any help will be really appreciate it.
     
     
      Thanks in advance.
       mils
     
     
     
     
        If you reply to this email, your
          message will be added to the discussion below:
        http://spssx-discussion.1045642.n5.nabble.com/Find-the-first-second-third-drug-chosen-tp5719400.html 
     
     
        To start a new topic under SPSSX Discussion, email
        [hidden email] 
        To unsubscribe from SPSSX Discussion, click
          here .
        NAML
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"