removing a space from within a string?

1,865 views
Skip to first unread message

Brian Sauer

unread,
Sep 20, 2010, 11:42:59 AM9/20/10
to Stata Users Forum
I have two datasets and the subject ID is different in both. In the
primary data set the subject ID is a alpha-numeric string that looks
like SL045. In the second table there is a space between the city
reference and number - it looks like SL 045. I want to remove the
space between SL 045 so I can join the tables.

I have tried substring, itrim and subinstr functions but haven't been
able to solve this one. Thought the subinstr would work but hasn't.

Is there something wrong with this approach?

replace patient_ID = subinstr(patient_ID, " ", "")

Any help will be greatly appreciated.
thanks,
Brian

Ken M

unread,
Sep 20, 2010, 2:16:57 PM9/20/10
to Stata Users Forum
Hi Brain,

Perhaps you missed the last argument of subinstr().

gen patient_ID = .
replace patient_ID = subinstr(patient_ID, " ", "", .)

With addition of period, this line worked fine.

HTH,
Ken
Reply all
Reply to author
Forward
0 new messages