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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
bkq32
Quartz | Level 8

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 */

View solution in original post

5 REPLIES 5
Jagadishkatam
Amethyst | Level 16

Could you please try the below code

 


x "cp A:\\HOST\SHARE\DATA\thedata.mdb   \\PATH2\'My Studies'\SAS\&foldername\site1";
Thanks,
Jag
Kurt_Bremser
Super User

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.

keen_sas
Quartz | Level 8

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

Kurt_Bremser
Super User

@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).

bkq32
Quartz | Level 8

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 */

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 9462 views
  • 0 likes
  • 4 in conversation