ATTRC Function

Returns the value of a character attribute for a SAS data set.

Category: SAS File I/O

Syntax

Required Arguments

data-set-id

specifies the data set identifier that the OPEN function returns.

attr-name

is the name of a SAS data set attribute. If the value of attr-name is invalid, a missing value is returned. The following is a list of SAS data set attribute names and their values:

CHARSET

returns a value for the character set of the computer that created the data set.

empty string Data set not sorted
ASCII ASCII character set
EBCDIC EBCDIC character set
ANSI OS/2 ANSI standard ASCII character set
OEM OS/2 OEM code format

ENCRYPT

returns 'YES' or 'NO' depending on whether the SAS data set is encrypted.

ENGINE

returns the name of the engine that is used to access the data set.

LABEL

returns the label assigned to the data set.

LIB

returns the libref of the SAS library in which the data set resides.

MEM

returns the SAS data set name.

MODE

returns the mode in which the SAS data set was opened, such as:

I INPUT mode allows random access if the engine supports it. Otherwise, it defaults to IN mode.
IN INPUT mode reads sequentially and allows revisiting observations.
IS INPUT mode reads sequentially but does not allow revisiting observations.
N NEW mode creates a new data set.
U UPDATE mode allows random access if the engine supports it. Otherwise, it defaults to UN mode.
UN UPDATE mode reads sequentially and allows revisiting observations.
US UPDATE mode reads sequentially but does not allow revisiting observations.
V UTILITY mode allows modification of variable attributes and indexes associated with the data set.

MTYPE

returns the SAS library member type.

SORTEDBY

returns an empty string if the data set is not sorted. Otherwise, it returns the names of the BY variables in the standard BY statement format.

SORTLVL

returns a value that indicates how a data set was sorted:

Empty string Data set is not sorted.
WEAK Sort order of the data set was established by the user (for example, through the SORTEDBY data set option). The system cannot validate its correctness, so the order of observations cannot be depended on.
STRONG Sort order of the data set was established by the software (for example, through PROC SORT or the OUT= option in the CONTENTS procedure).

SORTSEQ

returns an empty string if the data set is sorted on the native computer or if the sort collating sequence is the default for the operating environment. Otherwise, it returns the name of the alternate collating sequence used to sort the file.

TYPE

returns the SAS data set type.

Examples

Example 1: Writing a Message about Input Sequential Mode to the SAS Log

This example generates a message if the SAS data set has not been opened in INPUT SEQUENTIAL mode. The message is written to the SAS log as follows:
%let mode=%sysfunc(attrc(&dsid,MODE));
%if &mode ne IS %then
   %put Data set has not been opened in INPUT SEQUENTIAL mode.;

Example 2: Testing Whether a Data Set Has Been Sorted

This example tests whether a data set has been sorted and writes the result to the SAS log:
data _null_;
   dsid=open("sasdata.sortcars","i");
   charset=attrc(dsid,"CHARSET");
   if charset = "" then
      put "Data set has not been sorted.";
   else put "Data set sorted with " charset 
            "character set.";
   rc=close(dsid);
run;

See Also