|
Hays,
SAS does deliberately combine attributes from multiple FILE statements
in a single DATA step if they refer to the same fileref. (The same
principle applies to the INFILE statement.) I suspect this is to provide a
convenient shorthand in situations where, for instance, a user may be
switching back and forth between two output files in a single step, and
have several FILE statements referring to each. The convention they've
adopted saves the programmer from having to respecify the detailed
attributes on each FILE statement referring to the same file -- you can
specify them once, and treat the FILE statement as an output "switch" for
its other occurrences.
Try putting 3 FILENAME statements at the beginning of your program to
specify the physical file names, with a different fileref for each, rather
than specifying the physical names in the FILE statement. Then use the
filerefs rather than the physical names in the FILE statements. Haven't
tested it, but suspect it may work. Revised code (my changes in caps) and
original question below.
Mike Rhoads
Westat
RhoadsM1@Westat.com
FILENAME ONE 'TEST.TST';
FILENAME TWO 'TEST2.TST';
FILENAME THREE 'TEST.TST';
data; file ONE print notitles; put 'xyz';
do j=1 to 2;
if j=1 then do;
file TWO;
put 'xyz2';
end;
else do;
file THREE print notitles mod;
put 'xyz3';
end;
end;
run;
______________________________ Reply Separator _________________________________
Subject: Multiple file statements in one data step
Author: H.MCLEAN@PLUM.FRUIT.COM at internet-e-mail
Date: 8/16/96 3:44 PM
The following code is intended to print to (and overwrite) a file already on
the disk. The subsequent conditional statements are to print certain data to
a completely different file and to append certain data to the original print
file ... all in one data step. The problem is that apparently the MOD option
on the second FILE PRINT statement becomes operative throughout the data step.
So instead of overwriting the file to begin with, it appends everything to the
file on the disk.
If the statements are in separate data steps, it works.
Is there a reason for this or is it a bug?
data; file 'test.tst' print notitles;
put 'xyz';
do j=1 to 2;
if j=1 then do;
file 'test2.tst';
put 'xyz2';
end;
else do;
file 'test.tst' print notitles mod;
put 'xyz3';
end;
end;
run;
--Hays McLean
|