ATTRC Function

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

Category:SAS File I/O
Restriction:This function is not valid on the CAS server.

Syntax

Required Arguments

data-set-id

specifies the data set identifier that the OPEN function returns.

attribute-name

is the name of a SAS data set attribute. If the value of attribute-name is invalid, a missing value is returned. Here 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 stringdata set not sorted
ASCIIASCII character set
EBCDICEBCDIC character set
ANSIOS/2 ANSI standard ASCII character set
OEMOS/2 OEM code format

COMPRESS

returns a value that specifies how a data set is compressed.

CHARspecifies that the data set is compressed as character data.
BINARYspecifies that the data set is compressed as binary data.
NOspecifies that the data set is not compressed.

DATAREP

returns a value that indicates whether the data set is in a native format.

NATIVEindicates that the data set is in native format.
FOREIGNindicates that the data set is in a foreign 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:

IINPUT mode allows random access if the engine supports it. Otherwise, it defaults to IN mode.
ININPUT mode reads sequentially and allows revisiting observations.
ISINPUT mode reads sequentially but does not allow revisiting observations.
NNEW mode creates a new data set.
UUPDATE mode allows random access if the engine supports it. Otherwise, it defaults to UN mode.
UNUPDATE mode reads sequentially and allows revisiting observations.
USUPDATE mode reads sequentially but does not allow revisiting observations.
VUTILITY 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 stringData set is not sorted.
WEAKSort 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.
STRONGSort 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

Last updated: March 16, 2017