Sample 24599: Create multiple files from one data set
The sample code on the Full Code tab illustrates how to dynamically create multiple flat files using the FILEVAR= option.
Note: When creating multiple files with the FILEVAR= option, the files must have the same layout. When the value of the FILEVAR= variable changes, SAS closes the current file and opens a new file.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
/*******************************************************************************/
/* This example creates a new file for each BY-group in the existing data set. */
/* Each new file name is created by concatenting an incrementing counter */
/* variable to the end of the FNAME variable. */
/* */
/* Setting TEST by COLOR creates the new automatic varable FIRST.color, which */
/* is used to detect a new BY-Group. */
/* */
/* Note that DUMMY on the FILE statement acts as a placeholder. It is not */
/* acting as a fileref. The value of the FILEVAR= variable specifies the */
/* physical name of the file. */
/*******************************************************************************/
/* Create sample data */
data test;
input color $ num;
datalines;
blue 1
blue 2
blue 3
green 4
green 5
red 6
red 7
red 8
;
data _null_;
length fname $30.;
set test;
by color;
if first.color then count+1;
fname=cats("C:\TEMP\file",put(count,8.),".txt");
file dummy filevar=fname;
put color num count;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
FILE 1 OUTPUT
blue 1 1
blue 2 1
blue 3 1
FILE 2 OUTPUT
green 4 2
green 5 2
FILE 3 OUTPUT
red 6 3
red 7 3
red 8 3
Dynamically create multiple flat files using the FILEVAR= option.
Type: | Sample |
Topic: | SAS Reference ==> DATA Step Query and Reporting ==> Creating Reports ==> Non Graphical
|
Date Modified: | 2005-12-08 11:34:09 |
Date Created: | 2004-09-30 14:08:57 |
Operating System and Release Information
SAS System | Base SAS | All | n/a | n/a |