BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
vomer
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

6 REPLIES 6
art297
Opal | Level 21

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";

vomer
Obsidian | Level 7

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

Cynthia_sas
SAS Super FREQ

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
vomer
Obsidian | Level 7

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!

art297
Opal | Level 21

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.

vomer
Obsidian | Level 7

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

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


sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 53280 views
  • 8 likes
  • 3 in conversation