Announcement

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

  • Dash in directory

    Hi,

    I am having trouble with one of my directory that includes a dash.

    When I do :

    Code:
    local using "using "C:\Users\username\x.xlsx""
    
         if mi("`using'")==0  {
                export excel   treat   `using',    first(var) replace
            }
    No problems. But when I do:

    Code:
    local using "using "H:\.shortcut-targets-by-id\0B6x88ncMTfSOemMtd0tJN1hOaHc\x.xlsx""
         if mi("`using'")==0  {
                export excel   treat   `using',    first(var) replace
            }
    then I get an error "targets not found" .

    How do I specify my option using so that any kind of directory (especially the ones with dash as I never had problems before) would be accepted?


    Thanks

  • #2
    Ok found the solution using double quotations. The problem was from the if mi() not the export excel actually.


    Code:
     
     local using "using "H:\.shortcut-targets-by-id\0B6x88ncMTfSOemMtd0tJN1hOaHc\x.xlsx""      if mi(`""`using'""')==0  {             export excel   treat   `using',    first(var) replace         }

    Comment


    • #3
      Adrien Bouguen the way you are using multiple double quotes in defining the local macro is a recipe for possible problems of all sorts. I would recommend defining the local using compound quotes. Then everything should work fine down the line.

      Code:
      local using `"using "H:\.shortcut-targets-by-id\0B6x88ncMTfSOemMtd0tJN1hOaHc\x.xlsx"'

      Comment


      • #4
        Sorry, there was an error in my code (I was missing the closing double quote):
        Code:
        local using `"using "H:\.shortcut-targets-by-id\0B6x88ncMTfSOemMtd0tJN1hOaHc\x.xlsx""'

        Comment


        • #5
          Thanks Hemanshu!

          Actually the using local was included in syntax command. My original program looks like that:
          Code:
          cap program drop newprog
          program define newprog
          syntax varlist  using
          
          if mi("`using'")==0  { 
          export excel `varlist' `using' 
          }
          
          end
          If I run the command with a dash in the path:
          Code:
          newprog teachchar_pc1  using "H:\.shortcut-targets-by-id\0B6x88ncMTfSOemMtd0tJN1hOaHc\z.xlsx"
          I get an error.

          My fix was to simply do :

          Code:
          cap program drop newprog
          program define newprog
          syntax varlist  using
          
          if mi(`""`using'""')==0  { 
          export excel `varlist' `using' 
          }
          end
          which solves the problem. Do you see any issue doing that? Can I solve the problem differently?

          Best




          Comment


          • #6
            I would have written it as

            Code:
            cap program drop newprog
            program define newprog
            syntax varlist  using
            
            if !mi(`"`using'"')  { 
            export excel `varlist' `using' 
            }
            end
            which is to say, one pair of double quotes is redundant in the if command.

            Comment


            • #7
              Yes indeed. Thanks

              Comment

              Working...
              X