Announcement

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

  • typing "cd" gives error message "invalid syntax r(198);"

    Hello,

    I have entered the following code:

    global date 0702

    global path "C:\Users\[username]\Desktop\[folder]"
    global raw "$path\Data.dta"
    global programs "$path\Do.do"
    global output "$path\Sheet1.xlsx"

    clear
    set more off
    set segmentsize 3g


    No problem until now. But, when I enter
    cd $output
    I get the message
    invalid syntax
    r(198);


    I'm confused about where the problem lies and how I can fix it.

    Thanks for your help!

  • #2
    Welcome to Statalist.

    I see three possible problems, one of which causes the error message you received.

    First, in your actual definition of $path, I expect you have substituted your real username for "[username]" and a real directory name for "[folder]". If not, that will cause a problem, but not the one you experienced.

    Second, $output contains a file name, while the cd command requires a directory name. That too will cause a problem, but not the one you experienced.

    Third, I'd wager that the folder name you substituted for "[folder]" in your definition of $path has blank character in it. In general, best practices are to surround paths in quotation marks, especially if it is not immediately obvious that they contain a blank.
    Code:
    cd "$path"
    The embedded blank will cause exactly the problem you experienced: everything up to the blank is treated as a path, and everything after the blank is unexpected and generates a syntax error.

    Comment


    • #3
      You were right, and putting quotation marks solved the problem. Thanks a lot!!

      Comment


      • #4
        As a sidelight, this is why I never put spaces in directory names. Unfortunately some folder names are determined by the software you are using.
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        StataNow Version: 19.5 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://www3.nd.edu/~rwilliam

        Comment

        Working...
        X