LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (November 1996, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 14 Nov 1996 16:16:16 PST
Reply-To:   Melvin Klassen <KLASSEN@UVVM.UVIC.CA>
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   Melvin Klassen <KLASSEN@UVVM.UVIC.CA>
Subject:   Re: file statement and if/then-clause

Carina Ortseifen <Carina.Ortseifen@URZ.UNI-HEIDELBERG.DE> writes: >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'; /* "static" allocation of the file. */ > put x; > end; > else if x > 1 then do; > y = x*20; > end; > run;

Because the allocation is "static", SAS opens the file at the start of the DATA step. If you don't write anything, then the file will be "empty". Instead, to avoid writing the file when not needed, use:

data test; x=2; if x=1 then do; y = x*10; filename='xx.test'; drop filename; file dummy filevar=filename; /* Dynamically allocate the file. */ put x y; end; else if x > 1 then do; y = x*20; end; run;


Back to: Top of message | Previous page | Main SAS-L page