SAS Enterprise Guide

Desktop productivity for business analysts and programmers
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 3296 views
  • 0 likes
  • 4 in conversation