Date: Tue, 20 Apr 2004 12:30:27 -0400
Reply-To: Bruce Johnson <bjohnson@SOLUCIENT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Bruce Johnson <bjohnson@SOLUCIENT.COM>
Subject: Re: Outputting to multiple files
Content-Type: text/plain; charset="us-ascii"
Thanks so much! This is perfect!
________________________________
Bruce A. Johnson
bjohnson@solucient.com
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Richard A. DeVenezia
Sent: Tuesday, April 20, 2004 9:56 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Outputting to multiple files
Bruce Johnson wrote:
> I know that this works:
>
> Data a b c;
> set mydata;
> if condition=true then output a;
> else if condition2=true then output b;
> else output c;
> Run;
>
> But how do I do this when I want to output to flat files? Something
> like:
>
> Data _null_;
> set mydata;
> file file1;
> file file2;
> file file3;
> if condition=true then output file1;
> else if condition2=true then output file2;
> else output file3;
> Run;
>
> Can I do something like this in one step, or do I have to write a
> macro? The problem is that I have a 60 million record file that I
> don't want to
> have to loop through more than once if I can avoid it. The file is
> indexed on state, which is how I want to separate the file.
>
> Thanks.
First, writing to a flat file requires the PUT statement, not the OUTPUT
statement. Second, the FILENAME option you want to learn about is
FILEVAR=.
The value of the variable named by the FILEVAR option controls the name
of the operating system file that PUT writes go to.
The condition (state) you imply means there is a simple functional
mapping and you should not require wallpaper of at least 50 if/thens. If
the state values are significantly disordered the log can get very very
very very large and you might want to run with NONOTES.
data big;
input state $ x y z;
cards;
ny 1 2 3
nj 2 2 2
ny 3 2 1
ma 9 9 9
run;
%let putPath = %sysfunc(pathname(work));
* make sure destination is 'empty';
x "del &putPath.\*.txt";
data _null_;
set big;
putfile = "&putPath.\" || trim(state) || '.txt';
file dummy filevar=putfile dlm='09'x mod; * mod causes appending, and
is the reason the destination has to be initially empty;
put _all_;
run;
--
Richard A. DeVenezia
http://www.devenezia.com/downloads/sas/macros/?m=xmlib
This message is a private communication. It may contain information that is confidential
and legally protected from disclosure. If you are not an intended recipient, please do
not read, copy or use this message or any attachments, and do not disclose them to others.
Please notify the sender of the delivery error by replying to this message, and then
delete it and any attachments from your system.
Thank you,
Solucient LLC
(rev eXclaimer 2x)