Date: Tue, 12 Nov 1996 14:12:16 +0500
Reply-To: Bernard Tremblay <bernard@CAPITALE.QC.CA>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Bernard Tremblay <bernard@CAPITALE.QC.CA>
Subject: Re: file statement and if/then-clause
Hi,
Actually the "FILE" statement is executed at the start of
the data step. SAS does open the file for you, if it doesn't exist
it is created so you can write into it. At the end of the data step,
the file is closed, and if you didn't write into it, it should be empty.
If you don't want this to happen, you should retain a variable
and count the number of write into your file. Then, at end of the data step
you could decide to delete the file if it is empty.
Hope it helps,
Bernard Tremblay
\\\|///
\\ - - //
( @ @ )
+------oOOo-(_)-oOOo----------+---------------------------------+
| Bernard Tremblay | Bureau: (418) 646-2401 |
| La Capitale | Maison: (418) 878-4447 |
| |Internet: bernard@capitale.qc.ca |
| | bertrem@quebectel.com |
+---------------Oooo----------+---------------------------------+
oooO ( )
( ) ) /
\ ( (_/
\_)
>>>From owner-sas-l@UGA.CC.UGA.EDU Tue Nov 12 12:45 EST 1996
>>>Mime-Version: 1.0
>>>Content-Transfer-Encoding: 7bit
>>>Date: Tue, 12 Nov 1996 17:48:11 +0100
>>>From: Carina Ortseifen <Carina.Ortseifen@URZ.UNI-HEIDELBERG.DE>
>>>Subject: file statement and if/then-clause
>>>To: Multiple recipients of list SAS-L <SAS-L@UGA.CC.UGA.EDU>
>>>
>>>Dear SAS-L readers,
>>>
>>>today I have a question which was given to me by an user and I couldn't
>>>find an answer, I am only surprising about what SAS is doing.
>>>
>>>The problem is very simple. In a data step there is a if/then clause.
>>>Depending on a condition some statements will be executed.
>>>He wants to write data to file, if x is equal to 1. In the other case
>>>I will do nothing.
>>>
>>>But the phenomena is that if x is unequal 1 there will be allocated
>>>a file with 0 bytes. I tested it out for SAS 6.11 TS040 under Windows
>>>and SAS 6.11 TS020 under AIX.
>>>
>>>For demonstration you could examine the following program:
>>>
>>> data test;
>>> x=2;
>>> if x=1 then do;
>>> y = x*10;
>>> file 'xx.test';
>>> put x;
>>> end;
>>> else if x > 1 then do;
>>> y = x*20;
>>> end;
>>> run;
>>>
>>>After submitting I see in the log window:
>>>
>>> NOTE: The file 'xx.test' is:
>>> File Name=/afs/urz.uni-heidelberg.de/usr/urz/x16/xx.test,
>>> Owner Name=x16,Group Name=urz,
>>> Access Permission=rw-r--r--
>>>
>>> NOTE: 0 records were written to the file 'xx.test'.
>>> NOTE: The data set WORK.TEST has 1 observations and 2 variables.
>>> NOTE: DATA statement used:
>>> real time 3.59 seconds
>>> cpu time 0.70 seconds
>>>
>>>
>>>My questions:
>>>
>>>1. Why does SAS allocate the file xx.test?
>>>2. Are there other statements which will be executed ignoring the
>>> if condition?
>>>3. When I use the debugger for the data step, SAS will not pass the
>>> file statement. Does SAS execute this statement before it executes
>>> the datastep? Perhaps in the compilation phase?
>>>
>>>I would be very glad if there is someone who could explain this to
>>>me or could give me some hints where to look for in the manuals.
>>>--
>>>Mit freundlichem Gruss
>>>Kind Regards / Adios (Fuer Freunde/friends/amigos)
>>>Carina Ortseifen Carina
>>>
>>>+---------------------------------------------------------------------+
>>>| Dr. Carina Ortseifen Universitaet Heidelberg |
>>>| Universitaetsrechenzentrum |
>>>| Telefon: 06221/54-4541 Im Neuenheimer Feld 293 |
>>>| Electronic mail: D-69120 Heidelberg |
>>>| carina.ortseifen@urz.uni-heidelberg.de Telefax: 06221/54-5581 |
>>>| Jetzt auch im Internet: http://www.rzuser.uni-heidelberg.de/~x16/ |
>>>+---------------------------------------------------------------------+
|