Help using Base SAS procedures

rename statement with spaces in path

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

rename statement with spaces in path

Hi all,

I am trying to use the handy rename function (http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003122440.htm)s in  to change the name of external files.

This works:


DATA _NULL_;

  rc=rename("c:\testsas\file", "c:\testsas\file_renamed", 'file');

  PUT rc;

RUN;

But this does not work:

DATA _NULL_;

  rc=rename("c:\test sas\file", "c:\test sas\file_renamed", 'file');

  PUT rc;

RUN;

How can I get it to work when there are spaces in the directory/file?


Accepted Solutions
Solution
‎06-20-2015 12:33 AM
Respected Advisor
Posts: 4,173

Re: rename statement with spaces in path

Below code works for me with SAS9.4 under Win7. Are you 100% sure that the file you want to rename exists under your path?

DATA _NULL_;

  rc=rename("C:\test\name with blank\have.txt", "C:\test\name with blank\have_renamed.txt", 'file');

  PUT rc;

RUN;

View solution in original post


All Replies
Trusted Advisor
Posts: 3,215

Re: rename statement with spaces in path

Is avoiding spaces in file and/or directory names an answer? I have seen more issues on this with SAS. the problem is you need ^ at the oslevel arround the file/directory name. This "often ha a different meaning in Sas or in thé she'll in between. That is becoming a fight on to the ' and ". Sometimes disappearing magically.

---->-- ja karman --<-----
New Contributor
Posts: 2

Re: rename statement with spaces in path

Unfortunately we don't have rights to change some of the parent directories.

Trusted Advisor
Posts: 3,215

Re: rename statement with spaces in path

Did you try; embedding in single quotes as indication of a sas string and inner embedded with double quotes as of Windows allowing spaces?

You are seeing the ' and " close after each other.

'"Test folfder/file bsme"'

---->-- ja karman --<-----
Solution
‎06-20-2015 12:33 AM
Respected Advisor
Posts: 4,173

Re: rename statement with spaces in path

Below code works for me with SAS9.4 under Win7. Are you 100% sure that the file you want to rename exists under your path?

DATA _NULL_;

  rc=rename("C:\test\name with blank\have.txt", "C:\test\name with blank\have_renamed.txt", 'file');

  PUT rc;

RUN;

Super User
Posts: 7,854

Re: rename statement with spaces in path

Enclose the names in additional single quotes:

'"c:\testsas\file"', '"c:\testsas\file_renamed"'

and put a big sign up at the company's door:

DO NOT USE BLANKS IN FILENAMES

(all employees repeat 100 times during morning meditation)

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 325 views
  • 3 likes
  • 4 in conversation