Help using Base SAS procedures

renaming an external file

Reply
Regular Contributor
Posts: 161

renaming an external file

Hello SAS Experts,

I have a data file in my c directory named which I need to duplicate and rename.

The old data in "C" directory:

C:\CDM1\command.dat

I need to rplicate this to 100 files named :

C:\CDM1\CDM_1
C:\CDM1\CDM_2
C:\CDM1\CDM_3
C:\CDM1\CDM_4
and so on.

I appreciate any help.

Thank you
RG
Super Contributor
Super Contributor
Posts: 3,174

Re: renaming an external file

Look at using the CALL SYSTEM function from a DATA step -- you generate your OS command syntax. Recommend reviewing the particulars in the OS-specific SAS "companion" guide available on the SAS support http://support.sas.com/ website, where you will find SAS-hosted DOC but also supplemental technical and conference reference material, available using the website SEARCH or an Internet search engine.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search arguments, this topic / post:

call system site:sas.com

execute os commands site:sas.com
Super Contributor
Super Contributor
Posts: 365

Re: renaming an external file

Hello R.A.G

This is a solution:
[pre]
libname i "C:\CDM1";
%macro a;
%do i=1 %to 100;
data i.CDM_&i;
set i.command;
run;
%end;
%mend a;
.%a
[/pre]
The only question: is a command.dat a SAS dataset? If yes then this is the solution.
Sincerely,
SPR
Regular Contributor
Posts: 161

Re: renaming an external file

Thank you SPR
Regular Contributor
Posts: 161

Re: renaming an external file

The only problem is that command is a .dat file
Thank you
RG
Super User
Posts: 9,687

Re: renaming an external file

Hi.If your OS is Windows.
How about:
[pre]
data _null_;
file 'c:\copy.bat';
do i=1 to 10;
str=cats("copy c:\class.txt c:\class",i,".txt");
put str;
end;
run;
x "c:\copy.bat";
x "del c:\copy.bat";
run;
[/pre]



Ksharp
Regular Contributor
Posts: 161

Re: renaming an external file

thanks KSharp,
but No it doesn't work. It takes my command.INP file and wipes everything in it and turns it into a text file with these writen in it.
copy c:\command.inp c:\class1.inp
copy c:\command.inp c:\class2.inp
copy c:\command.inp c:\class3.inp
copy c:\command.inp c:\class4.inp
copy c:\command.inp c:\class5.inp
copy c:\command.inp c:\class6.inp
copy c:\command.inp c:\class7.inp
copy c:\command.inp c:\class8.inp
copy c:\command.inp c:\class9.inp
copy c:\command.inp c:\class10.inp

copy c:\command.txt c:\class10.inp
Regular Contributor
Posts: 161

Re: renaming an external file

Hello all,

Just to let you know I did get help from outside the Forums and found the code I am writing it here for those who are curious to know.

options noxwait noxsync;
data _null_;
do i = 1 to 2;
dosCommand="copy c:\cdm1\command.inp c:\cdm1\CDM" || strip(i) || ".INP";
put dosCommand;
call system(dosCommand);

end;

run;
Super User
Posts: 9,687

Re: renaming an external file

call system() is very boring because after executing call system every time you need to close the windows manually.

When you need 100 files ,then you need close the command windows manually for a hundreds times. Are you feeling tired with your finger?

And my code is only to close one command windows.



Ksharp
Super User
Posts: 9,687

Re: renaming an external file

Sigh..........
I only give you an example.
The only thing you need change is to change pathe and filename.


[pre]
data _null_;
file 'c:\copy.bat';
do i=1 to 10;
str=cats("copy c:\cdm1\command.dat c:\cdm1\cdm_",i,".dat");
put str;
end;
run;
x "c:\copy.bat";
x "del c:\copy.bat";
run;
[/pre]
Ask a Question
Discussion stats
  • 9 replies
  • 427 views
  • 0 likes
  • 4 in conversation