BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
alepage
Barite | Level 11

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;

View solution in original post

8 REPLIES 8
ballardw
Super User

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.

Tom
Super User Tom
Super User

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".

 

 

Kurt_Bremser
Super User

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

Patrick
Opal | Level 21

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

Kurt_Bremser
Super User

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.

alepage
Barite | Level 11
%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

alepage
Barite | Level 11
%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

alepage
Barite | Level 11

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;

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 860 views
  • 3 likes
  • 5 in conversation