For example, you could try using a different file name once.
options noxwait xsync;
x 'rename C:\Temp\test.csv text0.csv';
x 'rename C:\Temp\test1.csv text.csv';
x 'rename C:\Temp\test0.csv text1.csv';
The problem with the X statement is that it does not really tell you what happened. Use PIPE to retrieve the responses of the command:
data commands;
input command $80.; /* safe because DATALINES are always padded to at least 80 characters */
datalines;
rename C:\Temp\test.csv text0.csv
rename C:\Temp\test1.csv text.csv
rename C:\Temp\test0.csv text1.csv
;
data _null_;
set commands;
command = catx(" ",command,'2>&1'); /* reroutes stderr to stdout, so everything is caught */
infile dummy pipe filevar=command eof=done;
start:
input;
put _infile_;
go to start;
done:
run;
Untested, as On Demand runs with NOXCMD.
Please post the whole log of the data step in a code box (</> button).
If this has to be done in a sas session, using the rename function in a data step seems to be the best choice.
If your SAS runs on a remote server, you (most probably) cannot do this from SAS code. You would need to share your C: drive to the network and mount it on the SAS server.
Try using the RENAME() function.
Example:
* Create two files ;
data _null_;
file 'c:\downloads\file1.csv' ;
put 'file1';
file 'c:\downloads\file2.csv' ;
put 'file2';
run;
* Use the RENAME() function to "swap" them ;
data _null_;
if fileexist('c:\downloads\temp') then put 'Will not work because temp file already exists';
else do;
rc1=rename('c:\downloads\file1.csv','c:\downloads\temp','file');
rc2=rename('c:\downloads\file2.csv','c:\downloads\file1.csv','file');
rc3=rename('c:\downloads\temp','c:\downloads\file2.csv','file');
put (rc1-rc3)(=);
end;
run;
* check that it worked ;
data _null_;
infile 'c:\downloads\file1.csv' ;
input;
put _infile_;
infile 'c:\downloads\file2.csv' ;
input;
put _infile_;
run;
Maxim 14 says "Use the Right Tool".
When you can do a complex action with a one line system command instead of 100 lines of SAS code (and much quicker at that!), there is no question which is the better option.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: