Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AW: st: Working with complex strings


From   "Trelle Sven" <[email protected]>
To   <[email protected]>
Subject   AW: st: Working with complex strings
Date   Wed, 30 Nov 2011 09:48:04 +0100

This might be of help in your situation:

http://www.stata.com/support/faqs/data/regex.html

http://www.ats.ucla.edu/stat/stata/faq/regex.htm

I would do something like (although I acknowledge that there are probably more elegant/sophisticated solutions ...):

1. Identify the dose using regular expression (basically you want to identify the first number i.e. 1-9 and you wouldn't care about the rest of the dose e.g. you wantto identify the "1" in "150mg")
2. Identify the position where the dose (number) starts in your string using strpos()
3. Extract the medication using substr()

This assumes that your string variable always starts with the medication and that the drug name is directly followed by the dose (number) and that medication contains only drug name if no dose is given (as in your example).

* Code starts 
gen dig1 = regexs(0) if(regexm(medication, "[0-9]"))
gen drug =  trim(substr( medication,1,strpos( medication, dig1)-1)) if dig1!=""
replace drug = medication if dig1==""
* Code ends

Best
Sven
 


> -----Ursprüngliche Nachricht-----
> Von: [email protected] [mailto:owner-
> [email protected]] Im Auftrag von Dudekula, Anwar
> Gesendet: Mittwoch, 30. November 2011 06:44
> An: '[email protected]'
> Betreff: RE: st: Working with complex strings
> 
> Thank you very much
> 
> I will work on it .Would the parse() option split metoprolol tatrate 150mg bid
> as
> 
> metoprolol tatrate and 150mg bid
> 
> Or
> 
> metoprolol & tatrate & 150mg &  bid
> 
> Thank you
> Anwar
> 
> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Steve Nakoneshny
> Sent: Wednesday, November 30, 2011 12:38 AM
> To: [email protected]
> Subject: Re: st: Working with complex strings
> 
> - help split - would have answered this question.
> 
> - split medication, parse( ) -
> 
> should do what you want.
> 
> Steve
> 
> Sent via carrier pigeon
> 
> On Nov 29, 2011, at 9:54 PM, "Dudekula, Anwar" <[email protected]>
> wrote:
> 
> > Dear Stata List Reader,
> >
> > I am working with deidentified hospitaldatabase with patient names(as
> string variable) and medications (as string variable)as follows
> >
> > Patients_name        medication
> > ------------------------------------
> > Patient-1            metoprolol 100 mg qday
> > Patient-1            metoprolol tatrate 150mg bid
> > Patient-1            atenelol 150 mg qday
> > Patient-2            hctz 25 mg qday
> > Patient-2            PEG interferon
> > Patient-3            cimzia 50 mg qday
> >
> > Question: I am interested in name of medication only , not their dosages.Is
> it possible to split  the medication string  after the name  i.e.,
> >
> > 1) split  metoprolol tatrate 150mg bid into  metoprolol tatrate  &  150mg bid
> > 2) split  metoprolol 100 mg qday into   metoprolol   &   100 mg qday
> >
> > Thank you,
> > Yours Sincerely,
> > Anwar
> >
> >
> > *
> > *   For searches and help try:
> > *   http://www.stata.com/help.cgi?search
> > *   http://www.stata.com/support/statalist/faq
> > *   http://www.ats.ucla.edu/stat/stata/
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
> 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index