- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
using an X command to copy a file:
x 'copy
"C:\temp\sample.xls"
"C:\temp\sample2.xls"';
But now I'd like sample2 to be a macro variable, but it won't resolve inside the single quotes (I'm assuming). How would I go about getting this to work? I'm on SAS 9.2
%let my_var=test;
x 'copy
"C:\temp\sample.xls"
"C:\temp\&test..xls"';
Thanks!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Reeza,
The entire string after X is in single quotes ... and I know that you know that macro variables don't resolve within single quotes. Reverse them: double quotes on the outside and single quotes on the inside.
Alternatively, you could replace X with %SYSEXEC and you wouldn't need the outer quotes.
Good luck.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Reeza,
The entire string after X is in single quotes ... and I know that you know that macro variables don't resolve within single quotes. Reverse them: double quotes on the outside and single quotes on the inside.
Alternatively, you could replace X with %SYSEXEC and you wouldn't need the outer quotes.
Good luck.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I tried reversing the quotes and it doesn't work .
%sysexec works perfectly, Thanks Astounding
%sysexec copy "file1.xls" "&file_name..xls";
Message was edited by: Reeza
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Reeza
I have a very little to add but it seems a bit significant..
Although Tom has provided a most reliable way of ensuring a string is properly quoted even if you are unsure of what it contains (by using the quote() function) there is a simpler way that is also very generalised - when seeking to deliver quote marks within a string that is quoted(with the same kind of quotes) repeat the embedded quote - for example
x "copy
""C:\temp\sample.xls""
""C:\temp\&test..xls"" ";
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I had tried that as well Peter, but it didn't work on the system I was on. I'll retry again tomorrow to verify.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I tried to used the same command by extending in a do loop. But it did not work as expected.
OPTIONS NOXWAIT NOXSYNC;
%macro zxc;
%do i= 1 %to 68;
%SYSEXEC copy "D:\temp\&&memname&i." "c:\temp\&&memname&i.";
%end;
%mend zxc;
%zxc;
In The macro arrray &&memname&i, only the counter "i" is getting resolved.
SYMBOLGEN: Macro variable I resolves to 1
SYMBOLGEN: Macro variable I resolves to 1
SYMBOLGEN: Macro variable I resolves to 2
SYMBOLGEN: Macro variable I resolves to 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
To allow you to specify filenames with embedded spaces DOS wants you to enclose your filenames in dquotes.
To allow your macro variables to expand SAS wants you to enclose the full command in dquotes.
I have found that the QUOTE function helps with this.
%let my_var=My Goofy Filename;
x %sysfunc(quote(copy "C:\temp\sample.xls" "C:\temp\&test..xls")) ;