Thursday, March 09, 2006

st: RE: string function

I have produced something similar before... and with a few tweaks, here it is. The following code strips numbers and decimal points from the start of the lab variable (storing these in num) until it finds any character that is not a number or a decimal point (storing the remainder in unit).

gen num="" gen unit=lab tempvar c l gen `c'="" gen `l'=length(lab) su `l', meanonly local maxl=r(max) forvalues i=1/`maxl' { replace `c'=substr(unit,1,1) replace num=num+`c' if strpos("0123456789.",`c') replace unit=substr(unit,2,.) if strpos("0123456789.",`c') }


-----Original Message----- From: [] On Behalf Of Andy Choi Sent: 08 March 2006 21:51 To: Subject: st: string function

I have a large file with patient's labs. The lab variable contains the lab result (a number) with the units (for example mg/dl) included. There are many variations to the way the units are reported: they may be capitalized or in parentheses or the units themselves may contain numbers.

I would like to create a variable that includes only the lab result. And if possible a separate variable with the units.

Thanks, Andy

______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit ______________________________________________________________________

* * For searches and help try: * * *


Links to this post:

Create a Link

<< Home

This page is powered by Blogger. Isn't yours?