Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Escaping special characters

    Hi, Any clue to get back the whole string, not partial, escaping $ character ?

    . local word "$Gutf8&rtf$tf$JH$"

    . di "`word'"
    &rtf$


    thanks, Luis

  • #2
    Each time Stata sees something with a $ it thinks it is a global macro and will try to evaluate it, and if it does not exist then it will replace it with nothing. Notice that in your two lines of code there are two places where it could see those "global macros". First, when you define the macro. Second, if you solved that problem, you now run into the same problem again when you try to display it again (or use it in some other way).

    You first need to prevent Stata from trying to evaluate the "global macros" in your string, which you do with the escape character \

    Code:
    local word "\$Gutf8&rtf\$tf\$JH\$"
    Than you need to prevent Stata from trying to evaluate those "global macros" when display it again, which you do with the macro expansion function `macval()'

    Code:
    di "`macval(word)'"
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Maarten, thks for your quick reply.

      Actually, this escaping issue has broader implications. For example:

      odbc load, table("tabela") conn("DRIVER={SQL Server};DATABASE=;SERVER=;Trusted_Connection=;UID= ;PWD=$Gurtf$tf$JH$;") returns error and I, now, assume you found the reason.

      How Would I insert macro expansion function `macval()' in ODBC connection string context ?

      Last edited by Luis Pecht; 16 Sep 2020, 08:20.

      Comment

      Working...
      X