Help using Base SAS procedures

Copying Files from one directory to another

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 117
Accepted Solution

Copying Files from one directory to another

Hi Guys,

I have been trying to get this code to work...but no luck so far:

%let drive=I:;

%let dir1=%nrbquote("AB&C\Reports & Tests\ABC\My Codes\01Jan12");

%let dir2=%nrbquote("AB&C\Reports & Tests\Test ABC\01 - Jan 2012\Test Code");

%sysExec &drive move "&dir1\Code_to_Move.sas" "&dir2" /y ;

I get the error message "system cannot find the path specified" in the command prompt. I think it is due to the spaces and the "&" in the folder names but I cannot seem to fix it.

Basically trying to copy over a file from one folder to another. Please advise.


Accepted Solutions
Solution
‎02-03-2012 11:49 AM
PROC Star
Posts: 7,363

Copying Files from one directory to another

I didn't include the /y part as I don't have time to look it up right now, but the following worked for me:

%let drive=I:;

%let dir1=%nrstr(AB&C\Reports & Tests\ABC\My Codes\01Jan12);

%let dir2=%nrstr(AB&C\Reports & Tests\Test ABC\01 - Jan 2012\Test Code);

%sysExec move "&drive.\&dir1\Code_to_Move.sas" "&drive.\&dir2";

View solution in original post


All Replies
Solution
‎02-03-2012 11:49 AM
PROC Star
Posts: 7,363

Copying Files from one directory to another

I didn't include the /y part as I don't have time to look it up right now, but the following worked for me:

%let drive=I:;

%let dir1=%nrstr(AB&C\Reports & Tests\ABC\My Codes\01Jan12);

%let dir2=%nrstr(AB&C\Reports & Tests\Test ABC\01 - Jan 2012\Test Code);

%sysExec move "&drive.\&dir1\Code_to_Move.sas" "&drive.\&dir2";

Frequent Contributor
Posts: 117

Copying Files from one directory to another

thanks art!! that works. I guess I was positioning the drive macro in the wrong place.

SAS Super FREQ
Posts: 8,743

Re: Copying Files from one directory to another

Hi:

  You might want to work with Tech Support on this. In referring to the documentation,

http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000171045.htm

I find this note which may be relevant to your particular situation (highlighting is mine):

"The %SYSEXEC statement is analogous to the X statement and the X windowing environment command. However, unlike the X statement and the X windowing environment command,
host commands invoked with %SYSEXEC should not be enclosed in quotation marks." So it is possible that your %nrbquote, for the DIRx macro variables is messing you up somehow.

I know that your WHOLE command is not enclosed in quotation marks, but it seems that there is something about quotes that is or could be as much of an issue as your other special characters.

So, as with anything macro, until you open a track with Tech Support, here's what I'd suggest to debug:

1) take the special characters out of the picture and take macro variables out of the picture

  -- make 2 directories without ANY special characters like c:\aaa and c:\bbb\Code and test

      a working %SYSEXEC without ANY macro variables or special characters:

%sysExec c: move aaa\Code_to_Move.sas bbb\Code /y ;  (however, I think this syntax of the MOVE command is incorrect, see screenshot)

2) Once you get THAT syntax working without ANY macro variables and you know that your file is moved correctly, then make directories that have spaces (and only spaces in the name) and modify your MOVE command to get the code working with just spaces in the name.

3) Once you get THAT syntax working, still without any macro variables, then alter your hardcoded MOVE command to get the code working with your directories that have spaces and special characters.

But, even before you do any of that, step 0,  you have to be sure that the syntax of the MOVE command is correct. I'm not exactly sure what operating system you are using, but when I tried the MOVE command with /y at the end of the command, I got an error message in the DOS window. (see screenshot entitled example_move_command.jpg) So, perhaps, perfecting the syntax of the MOVE command is where you should start.

I do not expect that the string Reports & Tests will give you an issue because the & is separated from any text by a space on each side. I would expect that if you are having macro issues, the issue is with the &C in the first directory name because there is nothing to separate the & from the C in the string AB&C. But, even before that, with macro out of the picture, I can generate a "system cannot find the path specified" if I get some piece of the name wrong, the file does not exist, or the target path is misspelled or doesn't exist (see screenshot entitled cannot_find_file_path.jpg)

cynthia


cannot_find_file_path.jpgexample_move_command.jpg
Frequent Contributor
Posts: 117

Re: Copying Files from one directory to another

Guys I have 1 more question. How can I modify this so that it copies over all directories AND subdirectories??

%sysExec copy "&drive.\&dir1\*" "&drive.\&dir2";

Thanks!

PROC Star
Posts: 7,363

Re: Copying Files from one directory to another

Use the xcopy command.  See, e.g., http://support.microsoft.com/kb/240268

However, at the end of the part where you identify the files, you may want to use *.* rather than just *.  The xcopy command also provides a number of options.

Frequent Contributor
Posts: 117

Re: Copying Files from one directory to another

Thanks art! So silly of me not to try that. This worked:

%sysExec xcopy "&drive.\&dir1\*.*" "&drive.\&dir2" /E;


☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 19381 views
  • 4 likes
  • 3 in conversation