Exporting to directory with single quote in it

Reply
Super Contributor
Posts: 418

Exporting to directory with single quote in it

How would one export to a directory that has a single quote in it's name?    Example: Say I had a file directory that was I:\projects\Brandon's Files.  (i realize how bad it is to create a directory with a single quote, but that is not important to the question).... Anyways, when I run

data testme;

test=1;

run;

proc export data=testme outfile="I:\projects\Brandon's files\dontwork.xls" replace;

run;

I get the error

ERROR: Option "s" is not known for LIBNAME

133       data _EXCEXP.'testme'n;

WARNING: End-of-file encountered in string.

It looks like the system doesn't recognize that the single quote is part of the name, and not the start of a string literal....

I tried defining the string in a filename statement like so.

filename mydata "I:\projects\Brandon's Files\dontwork.xls"  and then changing the project export too...

proc export data=testme outfile=mydata replace;

run;

However I get the exact same error. Seems like the system cannot recognize that the single quote is actually part of the file reference location, and not the start of an actual string....

The ONLY Way i've been able to 'solve' this is by adding a secondary quote into the file path WHENEVER a first quote is found.. AKA changing my file path location too..

proc export data=testme outfile="I:\projects\Brandon''s files\dontwork.xls" replace;

run;

However I frankly don't feel like this is a valid solution, as I would then basically have to write code toi check for single quotes in ANY file name, or ANY path directory, any time I write or read data from them... Is there a way around this?

Thanks very much!

Super User
Super User
Posts: 6,367

Re: Exporting to directory with single quote in it

Did you try adding another layer of quotes so that SAS can pass a quoted filename to the operating system?

You might need to add the DBMS= option since SAS might get confused about what export engine you want.

proc export data=testme replace

  outfile=%sysfunc(quote("I:\projects\Brandon's files\dontwork.xls"))

  dbms=excel

;

run;

Valued Guide
Posts: 3,206

Re: Exporting to directory with single quote in it

As long it are directory names. Isolate them with a filename at an initial part code.

             eg:  - filename filebrn "I:\projects\Brandon''s files"  ; 

    than use: -   filebrn(dontwork.xls)   - as your coding.

It will make your code also better portable to other environments.

---->-- ja karman --<-----
Grand Advisor
Posts: 9,593

Re: Exporting to directory with single quote in it

Try another Engine .

proc export data=sashelp.class outfile="c:\temp\Brandon's files\dontwork.xls" dbms=xls replace;

run;

401  proc export data=sashelp.class outfile="c:\temp\Brandon's files\dontwork.xls" dbms=xls replace;

402  run;

NOTE: The export data set has 19 observations and 5 variables.

NOTE: "c:\temp\Brandon's files\dontwork.xls" file was successfully created.

NOTE: PROCEDURE EXPORT used (Total process time):

      real time           0.10 seconds

      cpu time            0.01 seconds

Xia Keshan

Ask a Question
Discussion stats
  • 3 replies
  • 400 views
  • 0 likes
  • 4 in conversation