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:
x '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.
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(%'));
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(%'));
Thanks polingjw it worked like a charm.
I just thought of an easier solution. Just remove the single quotes from your original X statement, as this syntax is not required.
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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.