BookmarkSubscribeRSS Feed
apple
Calcite | Level 5

How do i write out the same file to different locations?

 

Eg, i tried 2 file statements, but i realised the file in the first statement is empty.

 

 

 

FILENAME OUT 'C:\desktop\dataset1.dat'
FILENAME OUT1 'C:\desktop\data\dataset1.dat'
 
 
'
 


data out; Set dataset1; File out; File out1; put @1 variable1; run;

 

 
 

 

3 REPLIES 3
Kurt_Bremser
Super User

You can only write to one file at any given moment; that is why the first file is empty, as the second file statement takes precedence.

 

This is where a macro may be handy to avoid writing several data steps:

%macro write_file(outfilename);
data _null_;
set dataset1;
file "&outfilename";
put @1 variable1;
run;
%mend;
%write_file(C:\desktop\dataset\out);
%write_file(C:\desktop\out);
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

You can do something like this:

data _null_;
set sashelp.class;
file 's:\temp\rob\test1.txt';
put _all_;
file 's:\temp\rob\test2.txt';
put _all_;
run;

You can put as many file and put statements as you like.

 

Why are you using .dat extension by the way?  Use a descriptive file extension, so maybe .txt as it is textual file format, or .csv for comma separated.

Ksharp
Super User
If you can use OS comman , you can copy any number of file:

x  " copy c:\temp\rob\test1.txt  c:\temp\rob\test2.txt  ";


SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

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
  • 3 replies
  • 1127 views
  • 2 likes
  • 4 in conversation