- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I'm new to the x command and am following a previous employee's code that copies a file (thedata.mdb) from a location on their A drive to a new folder on their A drive.
option noxwait;
x "net use /yes A:\\HOST\SHARE\PATH1";
x "cd PATH2\'My Studies'\SAS";
x "md quarterly&sysdate";
%let foldername=quarterly&sysdate;
x "cd PATH2\'My Studies'\SAS&foldername";
x "md site1";
x %unquote(%str(%"copy A:\\HOST\SHARE\DATA\thedata.mdb
\\PATH2\'My Studies'\SAS\&foldername\site1%"));
I have read-only access to the A drive, so how do I modify this program so that the file is copied from their A drive to a newly created folder on my B drive (B:\\HOST\SHARE\site1\mydata.mdb)? I'd also like the the quarterly folder directory to be B:\\HOST\SHARE\quarterly20OCT19.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, everyone. I ended up doing this:
option noxwait;
%let foldername=quarterly&systdate;
x "md B:\HOST\SHARE\site1";
x "md B:\HOST\SHARE\&foldername";
x %unquote(%str(%'copy A:\HOST\SHARE\site1\thedata.mdb
B:\HOST\SHARE\site1\thedata.mdb%')); /* The actual path has spaces */
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Could you please try the below code
x "cp A:\\HOST\SHARE\DATA\thedata.mdb \\PATH2\'My Studies'\SAS\&foldername\site1";
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You should run all your external commands with the filename pipe method to see the responses:
filename oscmd pipe "net use /yes A:\\HOST\SHARE\PATH1 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
You can see all responses (standard and error output) in the SAS log. This makes it easier to diagnose each single command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
While trying to copy the file from one folder to other using the infile and PIPE , i am getting the below message in log. What could be the possible reason for not getting copied. What should be done to avoid the below text and any modification to the below code.
data _null_;
set newfile ;
cmd=catx(' ','copy',quote(catx('/',"&source",source)),quote("&target"));
infile cmd pipe filevar=cmd end=eof;
do while(not eof) ;
input;
put _infile_;
end;
run;
/bin/ksh: copy: not found
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@keen_sas wrote:
While trying to copy the file from one folder to other using the infile and PIPE , i am getting the below message in log. What could be the possible reason for not getting copied. What should be done to avoid the below text and any modification to the below code.
data _null_;
set newfile ;
cmd=catx(' ','copy',quote(catx('/',"&source",source)),quote("&target"));
infile cmd pipe filevar=cmd end=eof;
do while(not eof) ;
input;
put _infile_;
end;
run;
/bin/ksh: copy: not found
Your error message originates from a UNIX system; from the fact that it uses ksh (Korn Shell), I take it your SAS runs on AIX.
The command on AIX for a file copy is cp, not copy.
Note that you only need the quote functions if your path or file names contain blanks (something which any UNIX admin truly abhors).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, everyone. I ended up doing this:
option noxwait;
%let foldername=quarterly&systdate;
x "md B:\HOST\SHARE\site1";
x "md B:\HOST\SHARE\&foldername";
x %unquote(%str(%'copy A:\HOST\SHARE\site1\thedata.mdb
B:\HOST\SHARE\site1\thedata.mdb%')); /* The actual path has spaces */