DATA Step, Macro, Functions and more

Facing problem while cut pasting files using X command

Accepted Solution Solved
Reply
Contributor
Posts: 35
Accepted Solution

Facing problem while cut pasting files using X command

Hi,

I am trying something very simple. Just cutting a file (for example doc file) from one loacation and pasting it to another using X command. This should not be a problem but whenever I am using a Macro variable to resolve folder location I am facing problems.

The simple code is:

'move "C:\Data\Learning Products\New Folder\New Microsoft Word Document.doc" "C:\Data\Learning Products"';

This is running perfectly and giving me desired results.

But when I am running the same code using Macro variables:

%let abc=New Folder;

%let xyz=New Microsoft Word Document.doc;

X 'move "C:\Data\Learning Products\&abc.\&xyz" "C:\Data\Learning Products"';

This Code is not working and in the DOS window I am getting: 'The System could not find the file specified' error.

Can anyone please point out the error I am making in the second code?

Thanks in advance for your effort.


Accepted Solutions
Solution
‎12-29-2011 06:31 AM
Regular Contributor
Posts: 171

Re: Facing problem while cut pasting files using X command

The problem is that the macro variables are not resolved inside the single quote marks.  Try using this:

x %unquote(%str(%')move "C:\Data\Learning Products\&abc\&xyz" "C:\Data\Learning Products"%str(%'));

View solution in original post


All Replies
Solution
‎12-29-2011 06:31 AM
Regular Contributor
Posts: 171

Re: Facing problem while cut pasting files using X command

The problem is that the macro variables are not resolved inside the single quote marks.  Try using this:

x %unquote(%str(%')move "C:\Data\Learning Products\&abc\&xyz" "C:\Data\Learning Products"%str(%'));

Contributor
Posts: 35

Facing problem while cut pasting files using X command

Thanks polingjw it worked like a charm.

Regular Contributor
Posts: 171

Facing problem while cut pasting files using X command

I just thought of an easier solution.  Just remove the single quotes from your original X statement, as this syntax is not required.

Super User
Posts: 10,035

Facing problem while cut pasting files using X command

It is very intesting .

Another workaround way is to make a .bat file ,then use X command to execute it.

%let a=Task temp;
%let b=file.pdf;
data _null_;
 file 'c:\a.bat';
 a=catt('move "c:\',symget('b'),'" "c:\',symget('a'),'" ');
 put a;
run;
options noxwait;
x 'c:\a.bat';
x 'del c:\a.bat';

Ksharp

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 221 views
  • 0 likes
  • 3 in conversation