ASCII Files - Fixed Format
Previous Topic  Next Topic 

Stat/Transfer will read and write fixed format ASCII.


Standard extension: txt. csv


Reading Fixed Format ASCII Files

Stat/Transfer can read fixed format ASCII files.  These are data files where each field has a fixed column location and width, rather than having the start and end of the field marked by a delimiter character, as in delimited ASCII files.


Unlike the delimited ASCII format, where it is possible for Stat/Transfer to read the data based on the information contained in the data file, fixed format files require a separate description of each field's location in the record.  You will need to provide this information in a separate Stat/Transfer Schema file.  In the Schema file you can also define missing values, value and variable labels, and other characteristics of your data, as well as the path to the data file or the data file itself.


Using the User Interface

To use fixed format ASCII files as input into Stat/Transfer using the Stat/Transfer user interface, select "ASCII - Fixed Format (S/T Schema)" from the list of supported file types at the Input File Type line of the Transfer dialog box.


In the File Specification line of the Transfer dialog box, rather than entering the name of the fixed format ASCII file itself, enter the name of the Schema file that describes it.  Schema files will generally have the name of the input fixed format data file and the extension .sts.  The Schema file then points to the data file.  Thus, the location of the data file must be accurately given in the Schema file. If Stat/Transfer wrote the Schema file originally, then the exact path that Stat/Transfer used to write the ASCII file on your machine was entered as the file location in the Schema file.


The file location can be changed by opening up the Schema in any text editor, such as notepad, and giving the file location with the FILE command.  Comments in the first lines of the Schema or program file will guide you in changing the specified file location.


Using the Command Processor

To specify a fixed format ASCII file as input to Stat/Transfer when using the command processor, give the name of the Schema file as the input file in the COPY command. The file should have the extension .sts.  If for some reason your file does not have the extension .sts, then you can use the file-type tag stfixed.


The Schema file then points to the data file as described above.


Writing Fixed Format ASCII Data Files

On output, Stat/Transfer can write fixed format data files, and will, if directed, create a Stat/Transfer Schema file at the same time. Alternatively, you can choose to have Stat/Transfer write programs to accompany output fixed format ASCII files that will allow these files to be read into SAS, SPSS, or Stata.


Fixed format ASCII data files, along with the associated program files, are useful for passing your data to colleagues.  In addition, they are a prudent way to archive your data for future use, as they are not dependent on changes in computer architecture or the fate of a particular software package.


You have various options for writing out the program files.  If you are using the user interface, see ASCII/Text File Write and Date/Time Formats-Writing in the Options dialog box. For the command processor, see Available Options with the SET command.


Using the User Interface

When you click on the Output File Type control in the Transfer dialog box,  you will see the following entries in the list of supported output file types:


      ASCII/text - Fixed Format (S/T Schema)

                

      SAS Program + ASCII Data File

                

      SPSS Program + ASCII Data File

                

      Stata Program + ASCII Data File


ASCII/text - Fixed Format (S/T Schema)

This selection will write an ASCII data file plus a Stat/Transfer Schema file.


The Schema file name will appear in the output File Specification line of the Transfer dialog box.  Stat/Transfer constructs the output file specification by using the same drive (Windows), directory and name as the input file and appending the file extension .sts.  The output file itself will have the same name as the input and Schema files, but with the extension .dat.  The complete name and path of the output ASCII data file will be encoded in the Schema file.


The data file and Schema file can be read back by Stat/Transfer.  This is useful, for instance, if you want to add variable labels, value labels, and/or missing values to data stored in a file format that does not support these features.


For instance you could write the contents of an Excel spreadsheet to a fixed format ASCII file and then edit the contents of the Schema to add missing values or value labels that could then be transferred to SPSS, SAS or Stata.


XXX Program + ASCII Data File

The last three selections above


    SAS Program + ASCII Data File

    SPSS Program + ASCII Data File

    Stata Program + ASCII Data File


will each write a fixed format ASCII file along with a single program that will allow the file to be read into SAS, SPSS or Stata.  In addition, for the selection "Stata Program + ASCII Data File," a dictionary file will be written for Stata.


The program file name will appear in the output File Specification line of the Transfer dialog box.  Stat/Transfer constructs the output file specification by using the same drive (Windows), directory and name as the input file and appending the file extensions .sas, .sps, or .do. The output file itself will have the same name as the input and program files, but with the extension .dat.  If a Stata program file has been selected, the dictionary file will have the same name as the input and program files, but with the extension .dct.  The complete name and path of the output ASCII data file will be encoded in the program file.


You can then load the program file (that with the .sas, .sps, or .do extension) directly in SAS, SPSS or Stata to produce a data set with same name as the program file.  If necessary, the ASCII file specification encoded in the program files can be changed using any text editor that handles plain text (see below).


Using the Command Processor

You can write fixed format ASCII files using the command processor.


The only change from the description given above for using the user interface is that the type of output is specified by using an appropriate extension for the output file name in the COPY command, rather than making a selection from the dialog box.


The file extensions used to specify each type of output are:



Fixed format ASCII with a Schema file

.sts


Fixed format ASCII with a SAS program

.sas


Fixed format ASCII with an SPSS program

.sps


Fixed format ASCII with a Stata program

.do

   

Changing File Specifications in the Schema or Program File

When a fixed format ASCII file is used as input, either to Stat/Transfer with a Schema file or to SAS, SPSS or Stata with a program file, the first file that is read is either the Schema file or a program file.  This file then points to the actual data file.  Thus the location of the data file must be accurately given in the Schema or program file.


When the ASCII file with its accompanying Schema or program file is written on output, by default, the exact path that Stat/Transfer uses to write the output ASCII file on your machine will be entered as the file location in the Schema or program file.  If you change this behavior with the options for Generated Programs and Schemas in the ASCII/Text Write section of the Options dialog box, the output ASCII data file specification will be written to all of the program files using the directory "./" as the path.


The file location can be changed by opening up the Schema or program file in any text editor, such as notepad and giving the file location with the FILE command.  Comments in the first lines of the Schema or program file will guide you in changing the specified file location.


Missing Values

By default, missing values are indicated on input and output by a blank.  This behavior can be changed by setting the Numeric Missing Value option to "extended" in the ASCII Read or ASCII Write sections of the Options dialog box.


When an ASCII file with extended missing values is transferred to a SAS or a Stata file, the input missing values will transfer to the equivalent SAS ones.  When a SAS file is transferred to an ASCII file with extended missing values specified, any missing values '._' in the input SAS file are written out as  '.' in the output.


Output Variable Types

The output variable type that results from each target variable type is given in the following table:



Target Type

Output Type


byte

int

long

float

double

Number (with a precision of up to 15 decimal places)


string

Character


date

time

date/time

Character



See also:

Schema Files for ASCII Input