Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving output twice (can FILE command do this?)

Status
Not open for further replies.

jonnysnow

Programmer
Apr 10, 2003
36
US
I have a program that produces formatted output. What I want is to have SAS (1) send the output to the printer, and (2) save a copy of the formatted output.

I figured out how to send output to the printer--
Code:
filename laserjet printer;

data rpt1;
file laserjet;
put .....
put .....
.........
Is there any way to get SAS to also save this output to a file without repeating the DATA step? This DATA step modifies the input data, so if I just ran it a second time, it wouldn't work.

I know I can always save a copy of the input before it's modified. But if anyone has a better way, please let me know.

Thanks!
 
Why not change the sequence. First, send it to a file (text...) and then have a small data _null_ that sends the text file to a printer.

filename yourfile "c:\test.txt";
filename laserjet printer;

data rpt1;
file yourfile;
put .....;
...
run;

***SEND TO PRINTER;
data _null_;
infile yourfile;
file laserjet;
input;
put _input_;
run;

I haven't checked this but it should work. Let me know if you solve this.
I hope that this helps.
Klaz
 
That's terrific! It works beautifully.

One syntax correction. It's:
put _infile_; (not: put _input_)
 
An alternative method which will save you some CPU cycles:-

filename yourfile "c:\test.txt";
filename laserjet printer;

data _null_;
set my_dset;
file laserjet;
put ...;

file yourfile;
put ...;

run;

This'll save you reading in the same file twice, which is good if the dataset is particularly large. I played around with putting both filenames on the same file statement, but that didn't work unfortunately.

An alternative method is to use ODS. ODS allows you to have 2 output destinations open at the same time.

Something like :-

ODS PRINTER ....;
ODS CSV file="c:\myfile";

proc print data=my_dset;
run;

ODS CSV close
ODS PRINTER close;

You'll need to look up the proper syntax for ODS PRINTER though.

Enjoy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top