- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%let source=c:\New folder;
%let target=c:\shubham;
data source ;
infile "dir /b ""&source\"" " pipe truncover;
input fname $256. ;
run;
data target ;
infile "dir /b ""&target\"" " pipe truncover;
input fname $256. ;
run;
data new;
set source ;
length cmd1 $100.;
cmd1 = catx(' ','xcopy',quote(catx('\',"&source",fname)),quote("&target"));
cmd= cat('X ',cmd1);
infile cmd filevar=cmd end=eof ;
do while (not eof);
input;
put _infile_;
end;
run;
Below is the error that comes up
ERROR: Invalid physical name.
fname=file1.txt cmd1=xcopy "c:\New folder\file1.txt" "c:\shubham"
cmd=X xcopy "c:\New folder\file1.txt" "c:\shubham" eof=0 _ERROR_=1 _INFILE_= _N_=1
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 1 observations read from the data set WORK.SOURCE.
WARNING: The data set WORK.NEW may be incomplete. When this step was stopped there were 0
observations and 2 variables.
WARNING: Data set WORK.NEW was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
My goal is to copy all directories and subdirectories dynamically
how can I do that
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This line:
infile cmd...
As you can see from the error, CMD variable contains:
X xcopy "c:\New folder\file1.txt" "c:\shubham"
Which is not valid SAS syntax. Infile requires a path/filename, or fileref.
What is it your copying, what is the process? As I mentioned before, programs which create/copy folders/files should never really be needed. You process should take care of that - i.e. follow an operating procedure, be inline with IT requirements, permissions etc. Simply copying an pasting directories/files willy nilly will flag you up to IT.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
what I want is that I want to copy all the directories and subdirectories through sas
for ex-I wan to copy from old folder which contain file1.txt and file2.txt path- c:\old folder to a new path c:\new folder
how can I do this by SAS program
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I understand what you want, I don't understand why you want to do that. Its never a good idea to multiple your file system, it sounds like there is some reasoning as to copying that, maybe thats a fixed copy and you don't want to alter it? If so open it as read only and work with it in your work area - this is just an example.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
what i want is that whenver I run SAS program it should copy file from one directories to another
how caN i acheive that using SAS or any other way
please help me
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
filename oscmd pipe "xcopy c:\source\* c:\target /s /y 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
will copy all files in c:\source to c:\target, including all subdirectories. /y prevents prompting when a file already exists in the target.
The filename pipe and data step are used to catch output from the command and write it to the SAS log; if you don't need that, you can issue the xcopy command in a X statement.
I recommend doing the filename/data step method at least while testing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Rohit12 wrote:
%let source=c:\New folder;
%let target=c:\shubham;
data source ;
infile "dir /b ""&source\"" " pipe truncover;
input fname $256. ;
run;
data target ;
infile "dir /b ""&target\"" " pipe truncover;
input fname $256. ;
run;
data new;
set source ;
length cmd1 $100.;
cmd1 = catx(' ','xcopy',quote(catx('\',"&source",fname)),quote("&target"));
cmd= cat('X ',cmd1);
infile cmd filevar=cmd end=eof ;
do while (not eof);
input;
put _infile_;
end;
run;
Below is the error that comes up
ERROR: Invalid physical name.
fname=file1.txt cmd1=xcopy "c:\New folder\file1.txt" "c:\shubham"
cmd=X xcopy "c:\New folder\file1.txt" "c:\shubham" eof=0 _ERROR_=1 _INFILE_= _N_=1
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 1 observations read from the data set WORK.SOURCE.
WARNING: The data set WORK.NEW may be incomplete. When this step was stopped there were 0
observations and 2 variables.
WARNING: Data set WORK.NEW was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
My goal is to copy all directories and subdirectories dynamically
how can I do that
Looks to me like you want to execute the XCOPY with PIPE not X command. See if this works...
data new;
set source ;
length cmd1 $100.;
cmd1 = catx(' ','xcopy',quote(catx('\',"&source",fname)),quote("&target"));
infile dummy pipe filevar=cmd1 end=eof ;
do while (not eof);
input;
put _infile_;
end;
run;
Notice the change to the INFILE statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
No it does not works
below is the note that is coming in that's why it is not copying it
NOTE: The infile DUMMY is:
Unnamed Pipe Access Device,
PROCESS=xcopy "c:\New folder\file1.txt" "c:\shubham",
RECFM=V,LRECL=256
NOTE: The infile DUMMY is:
Unnamed Pipe Access Device,
PROCESS=xcopy "c:\New folder\file2.txt" "c:\shubham",
RECFM=V,LRECL=256
NOTE: The infile DUMMY is:
Unnamed Pipe Access Device,
PROCESS=xcopy "c:\New folder\great" "c:\shubham",
RECFM=V,LRECL=256
NOTE: The infile DUMMY is:
Unnamed Pipe Access Device,
PROCESS=xcopy "c:\New folder\harnem.zip" "c:\shubham",
RECFM=V,LRECL=256
NOTE: The infile DUMMY is:
Unnamed Pipe Access Device,
PROCESS=xcopy "c:\New folder\new file.txt" "c:\shubham",
RECFM=V,LRECL=256
NOTE: 0 records were read from the infile DUMMY.
NOTE: 0 records were read from the infile DUMMY.
NOTE: 0 records were read from the infile DUMMY.
NOTE: 0 records were read from the infile DUMMY.
NOTE: 0 records were read from the infile DUMMY.
let me know how can i correct this
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Rohit12 wrote:
No it does not works
below is the note that is coming in that's why it is not copying it
NOTE: The infile DUMMY is:
Unnamed Pipe Access Device,
PROCESS=xcopy "c:\New folder\file1.txt" "c:\shubham",
RECFM=V,LRECL=256
NOTE: The infile DUMMY is:
Unnamed Pipe Access Device,
PROCESS=xcopy "c:\New folder\file2.txt" "c:\shubham",
RECFM=V,LRECL=256
NOTE: The infile DUMMY is:
Unnamed Pipe Access Device,
PROCESS=xcopy "c:\New folder\great" "c:\shubham",
RECFM=V,LRECL=256
NOTE: The infile DUMMY is:
Unnamed Pipe Access Device,
PROCESS=xcopy "c:\New folder\harnem.zip" "c:\shubham",
RECFM=V,LRECL=256
NOTE: The infile DUMMY is:
Unnamed Pipe Access Device,
PROCESS=xcopy "c:\New folder\new file.txt" "c:\shubham",
RECFM=V,LRECL=256
NOTE: 0 records were read from the infile DUMMY.
NOTE: 0 records were read from the infile DUMMY.
NOTE: 0 records were read from the infile DUMMY.
NOTE: 0 records were read from the infile DUMMY.
NOTE: 0 records were read from the infile DUMMY.
let me know how can i correct this
The fact that xcopy does not give you any output usually means it worked as expected. Look in the target directory if the files are there.
If they're not there, run xcopy from the commandline outside of SAS and see if you get error messages.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
And with xcopy, you do not have to iterate through a directory structure, as xcopy is specifically designed to do that on its own (different form the simple copy).
Have you already tried this:
filename oscmd pipe 'xcopy "c:\New folder\*" "c:\shubham /s /y 2>&1';
data _null_;
infile oscmd;
input;
put _infile_;
run;
?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I've tried Kurt Bremser's solution and it doesn't work for me. I alose get a note
NOTE: 0 records were read from the infile OSCMD.
The destination folder remains empty. This is odd, the PIPE method works fine with other Windows shell commands such as copy, move, del.
A solution that does work is to sue robocopy.
robocopy "<source>" "<dest>" * /is
Robocopy (Robust File Copy for Windows) does have a quirk, you can't use a double period to go up one level in your program path. It also produces more output but that's not necessarily a problem. I hadn't heard of it until today, documentation is at https://technet.microsoft.com/nl-nl/library/cc733145(v=ws.10).aspx.
What interests me is why the xcopy command isn't being executed. Does anyone know?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Test the xcopy from the commandline before running it from SAS. Basically, the 2>&1 at the end of the command should redirect error messages to the pipe, though, so if something is amiss SAS should catch it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Kurt,
The xcopy command does work from a command line or if modified to a robocopy command. What's telling is the message "0 records were read". The command isn't generating an error, it's being completely ignored. But the equivalent robocopy command does work!
Does the xcopy command work for you? If so, what version of SAS are you using and on which platform? I'm using SAS 9.4M1 on a Windows 2008 server. I'm using Enterprise Guide but with the "xcmd" option enabled (by default, Enterprise Guide won't let you execute shell commands but our SAS administrator enabled this option).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Wow. I just checked and couldn't believe it. While other things work as they should, xcopy obviously plays "dead" when run from SAS. I simply couldn't believe that such a simple utility would do that.
Even after making sure that no further input would be expected from me.
Thank $DEITY I don't have to put up with such crap. My SAS runs on UNIX.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Can you use COPY to copy any of the files?
Perhaps it is a permission issue with the account that your SAS server is using?
http://stackoverflow.com/questions/24485086/xcopy-does-not-copy-all-files