I have a file Nflag which looks like this.
Flag
0
1
0
1
1
I also have a group of folders named:
Test1.nm7
Test2.nm7
Test3.nm7
Test4.nm7
Test5.nm7
What I would like to do is to have the folder names reflect the flag values so that those with a 0 (e.g.,0Test1.nm7) designation can be later deleted. What I would have initially would be:
0Test1.nm7
1Test2.nm7
0Test3.nm7
1Test4.nm7
1Test5.nm7
The final folders would be:
1Test2.nm7
1Test4.nm7
1Test5.nm7
Can someone tell me how best to do this?
This solution worked.
Hello,
Not sure exactly what your trying to achieve here. Do you want to modify the values in your dataset or you really want to rename the folders?
Create a BAT file(Windows OS) by sas. like:
data _null_;
set have;
file 'c:\temp\rename.bat';
x=' rename Test1.nm7 0Test1.nm7 '; /*<-- Change it based on HAVE dataset*/
put x;
run;
And execute c:\temp\rename.bat under Command Line (Start--> Run --> cmd )
OK. assuming you have a folder named c:\bootstrap ,
under it there are three sub-folders named :
Test1.nm7
Test2.nm7
Test3.nm7
Firstly , make a table contains 0 and 1.
data have;
input Flag;
cards;
0
1
0
;
Secondly, get the sub-folders name :
data folders;
rc=filename('x','c:\bootstrap');
did=dopen('x');
do i=1 to dnum(did);
folder=dread(did,i);
output;
end;
run;
Lastly ,make a BAT file if you could and execute BAT file.
Here is c:\temp\rename.bat .
Enter command line and type " c:\temp\rename.bat" to execute it .
filename x 'c:\temp\rename.bat';
data _null_;
merge have folders;
rename=catx(' ','rename',folder,cats(flag,folder));
file x;
if _n_=1 then put 'cd c:\bootstrap';
put rename;
run;
Did you create a folder named "bootout" under C:\ ?
c:\bootout is refer to a directory.
and under it ,create many sub-directory like Test1.nm7.
c:\bootout\Test1.nm7
c:\bootout\Test2.nm7
.........
This solution worked.
Can you post your ERROR information?
Did your directory name contains some special character like blank ? if it was ,you need quote around it to rename.
rename "1Test2 nm7" 1Test2.nm7
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.