Base SAS Encoding Behavior

Overview of Base SAS Encoding

For Base SAS files (not SPD Server), the encoding support depends on the version of SAS that created the file:
  • Data sets created in SAS 9 automatically have an encoding attribute, which is stamped in the descriptor portion of the file.
  • Data sets created in SAS 8 do not have an encoding value stamped on the file; they are assumed to be in the session encoding of the host environment.
The NLS features in SPD Server only support encoding from SAS 9.

SAS 9 Output Processing

For SAS 9 data sets (not SPD Server), encoding is determined as follows:
  • For a new output file, the data is written to the file using the current session encoding.
  • For a new output file that is created with the OUTREP= option, which specifies a data representation different from the current session, the data is written to the file using the default session encoding for the operating system that is based on the specified OUTREP= value.
  • For output processing that replaces an existing file, the new file inherits the encoding of the existing file.
  • For output processing that replaces an existing file that is from another platform or if the existing file has no encoding stamped on it, the current session encoding is used.

SAS 9 Input Processing

For input (read) processing in SAS 9 (not SPD Server), encoding behavior is as follows:
  • If the session encoding and the encoding that is stamped on the file are incompatible, the data is transcoded to the session encoding. For example, if the current session encoding is ASCII and the encoding that is stamped on the file is EBCDIC, SAS transcodes the data from EBCDIC to ASCII.
  • If a file does not have an encoding stamped on it, SAS transcodes the data only if the file's data representation is different from the current session.

Reading and Writing External Files

SAS reads and writes external files using the current session encoding. SAS assumes that the external file is in the same encoding as the session encoding. For example, if you are creating a new SAS data set by reading an external file, SAS assumes that the file's encoding is the same as the session encoding. If it is not, the data could be written to the new SAS data set incorrectly.