BookmarkSubscribeRSS Feed
natomajo
Calcite | Level 5

I would like to rename multiple file extensions from EU to txt using the below code result  but I dont get the desired results.

Please note that I am using the UNIX environment.

 

DATA _NULL_;
X 'rename /EIP/Data/Lev1/Data/FBM/.*EU /EIP/Data/Lev1/Data/FBM/*.txt';
RUN;

5 REPLIES 5
Astounding
PROC Star

A couple of items to fix this ...

 

First, note that SAS does not require a DATA step in order to run the X command.  You only need one line of code.

 

Second, note that you need a legitimate Unix command.  There is no "rename" command in Unix.  There is both "mv" and (I believe) "rnm".  So get your command working in Unix first, without using SAS.  Then it should be straightforward to convert it to a SAS X command.

ballardw
Super User

Also you may want to double check the location of the wildcard character * in the source part of the command

data_null__
Jade | Level 19

Do you really need to change the extension?  What will having the new extention get you that EU cannot provide.

natomajo
Calcite | Level 5

I did not know that you can an EU file using SAS, just tried it and it worked.

Really appreciated... But I would also like to know how to rename multiple files that resides in the same UNIX directory.

 

I used the below piece of code in windows environment and it worked..

 

filename ren pipe "dir C:\Users\Desktop\FBM\FILES\NEW\*.EU /b /s";
/*To get the corresponding new file names*/
data ren;
infile ren;
input old : $250.;
new=tranwrd(old,".EU",'.TXT');
run;
/*To rename them all*/
data _null_;
set ren;
rc=rename(old, new, 'file');
put rc;
run;

data_null__
Jade | Level 19

I think a similar program using SAS RENAME function would work in UNIX just as well as Windows.

 

I was fiddling with this one line bash script.  It does not exectue 'MV' just shows the command with ECHO.  It's really the same as your SAS program only different language.  I think most folk would do some kind of GREP thing but I'm not good with that.

 

  •  for file in x*.xml; do echo "Process: $file"; x=`basename $file .xml`; echo "mv $file ${x}.txt"; done;
  • For each file that matches the pattern x*.xml
  • print the file name
  • assign x the filename with .xml removed
  • print the mv command 
>for file in x*.xml; do echo "Process: $file"; x=`basename $file .xml`; echo "mv $file ${x}.txt"; done;
Process: xmltest.xml
mv xmltest.xml xmltest.txt
Process: xp1.xml
mv xp1.xml xp1.txt
Process: xp2.xml
mv xp2.xml xp2.txt

Assumes UNIX shell is BASH

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 2426 views
  • 0 likes
  • 4 in conversation