- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I have a file hosted on unix server who name is Virage Survey.xml
I would like to change the name for VirageSurvey.xml
I have tried this unix command directly on the terminal and it works
mv "path1/Virage Survey.xml" "path1/VirageSurvey.xml"
but in SAS EG I have tried this and nothing append.
x 'mv "path1/Virage Survey.xml" "path1/VirageSurvey.xml"';
Any suggestion
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello Kurt,
The use of the PIPE command was very usefull to diagnose the issue. Thank you very much.
Please, see the script below :
/** Renaming the XML File with SAS standard (no space in the file name) ***/
%let file_path=/finsys/.../data;
filename oscmd pipe "mv ""&file_path./Virage Survey.xml"" ""&file_path./VirageSurvey.xml"" 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What does your LOG show when you attempt that X command?
Did your path start at the root of the drive? If not then the path likely would have been treated relative to where SAS is executing and would typically not find the file.
And don't forget that UNIX file names and paths are case sensitive and upper case characters are a poor idea in general.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It is probably simpler to remove PATH from the problem. If you were doing this in a terminal window you would just do:
cd "path1" mv "Virage Survey.xml" "VirageSurvey.xml"
The quotes are required around any value that contains an embedded space, like your first name.
So to generate that in SAS code I would call the QUOTE() function to make sure the quotes are generated properly.
data _null_;
infile %sysfunc(quote(cd "path1" ; mv "Virage Survey.xml" "VirageSurvey.xml")) pipe ;
input;
put _infile_;
run;
And if you are moving the file from one directory to a different directory you need to make sure that both directories are on the same mounted disk volume. The mv command cannot copy a file to another disk. It just changes the directory entries. If you want to move to a different disk you will have copy first and then delete the original to get the effect of a "move".
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Tom I have to correct you. mv can in fact move files across devices. Only when it realizes source and destination are on the same device will it do a rename alone.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@alepage I assume this question is related to your other question here.
There is no need to rename this XML file only for the purpose to read the data into SAS. The content of the XML file does not depend on the name of the file. It's the content that determines the table names you'll get when converting the data to SAS tables. It's no issue at all if the XML file name does not comply with SAS naming standards for SAS tables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Don't use the X statement. Always use the PIPE method to see what happens:
filename oscmd pipe 'mv "path1/Virage Survey.xml" "path1/VirageSurvey.xml" 2>&1';
data _null_;
infile oscmd;
input;
put _infile_;
run;
You will see all responses in the SAS log. If nothing appears, the command worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%let file_path=/finsys/.../data;
filename oscmd pipe 'mv "&file_path./Virage Survey.xml" "file_path./VirageSurvey.xml" 2>&1';
data _null_;
infile oscmd;
input;
put _infile_;
run;
It seems that the &file_path. macro variable is not evaluated
Log:
NOTE: The infile OSCMD is:
2 The SAS System 08:43 Wednesday, January 31, 2024
Pipe command="mv "&file_path./Virage Survey.xml" "file_path./VirageSurvey.xml" 2>&1"
mv: cannot stat '&file_path./Virage Survey.xml': No such file or directory
NOTE: 1 record was read from the infile OSCMD.
The minimum record length was 74.
The maximum record length was 74.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%let file_path=/finsys/.../data;
filename oscmd pipe 'cd "&file_path." 2>&1';
data _null_;
infile oscmd;
input;
put _infile_;
run;
NOTE: The infile OSCMD is:
Pipe command="cd "&file_path." 2>&1"
2 The SAS System 08:43 Wednesday, January 31, 2024
/bin/bash: line 0: cd: &file_path.: No such file or directory
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello Kurt,
The use of the PIPE command was very usefull to diagnose the issue. Thank you very much.
Please, see the script below :
/** Renaming the XML File with SAS standard (no space in the file name) ***/
%let file_path=/finsys/.../data;
filename oscmd pipe "mv ""&file_path./Virage Survey.xml"" ""&file_path./VirageSurvey.xml"" 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi !
Nice solution, with pipe it is the only way it worked for me.
Regards, Miguel.