BookmarkSubscribeRSS Feed
R_A_G_
Calcite | Level 5
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
9 REPLIES 9
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
SPR
Quartz | Level 8 SPR
Quartz | Level 8
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
R_A_G_
Calcite | Level 5
Thank you SPR
R_A_G_
Calcite | Level 5
The only problem is that command is a .dat file
Thank you
RG
Ksharp
Super User
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
R_A_G_
Calcite | Level 5
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
R_A_G_
Calcite | Level 5
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;
Ksharp
Super User
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
Ksharp
Super User
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]

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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