Chapter Contents

Previous

Next
ATTRC and ATTRN

ATTRC and ATTRN



Return the value of an attribute for a SAS table

Category: SAS Table


Syntax
Attributes for the ATTRC Function
Attributes for the ATTRN Function
Examples
Example 1: Using the ATTRC Function
Example 2: Using the ATTRN Function
See Also

Syntax

attr-value=ATTRC(table-id,attr-name);
attr-value=ATTRN(table-id,attr-name);

attr-value
contains the value of the SAS table attribute. For ATTRC, the value is for a character attribute. For ATTRN, the value is for a numeric attribute.

Type: Character, Numeric

table-id
contains the identifier for the SAS table. This is the identifier that was returned by the OPEN function when the table was opened. If table-id is invalid, the program halts.

Type: Numeric

attr-name
is the name of the SAS table attribute. If attr-name is invalid, then a missing or null value is returned for attr-value. Values that can be used with ATTRC are listed in Attributes for the ATTRC Function. Values that can be used with ATTRN are listed in Attributes for the ATTRN Function.

Type: Character


Attributes for the ATTRC Function

To check for a character attribute of a SAS table, use ATTRC with one of the following values for attr-name:

'CHARSET'
returns a string indicating the character set of the machine that created the SAS table. It returns either one of the following values, or an empty string if the SAS table is not sorted:

ASCII
ASCII character set

EBCDIC
EBCDIC character set

HASCII
extended ASCII 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 table is encrypted.

'ENGINE'
returns the name of the engine used to access the SAS table.

'LABEL'
returns the label assigned to the SAS table.

'LIB'
returns the libref of the SAS data library in which the SAS table resides.

'MEM'
returns the name of the SAS data library member.

'MODE'
returns the mode in which the SAS table was opened, such as:
I INPUT mode, allows random access if the engine supports it; otherwise, defaults to IN mode
IN INPUT mode, reads sequentially and allows revisiting rows
IS INPUT mode, reads sequentially but does not allow revisiting rows
N NEW mode (to create a new SAS table)
U UPDATE mode, allows random access if the engine supports it; otherwise, defaults to UN mode
UN UPDATE mode, reads sequentially and allows revisiting rows
US UPDATE mode, reads sequentially but does not allow revisiting rows
V UTILITY mode, allows modification of column attributes and indexes that are associated with the SAS table.

For more information about open modes, see OPEN.

'MTYPE'
returns the type of the SAS data library member.

'SORTEDBY'
returns an empty string if the SAS table is not sorted. Otherwise, returns the names of the BY columns in the standard BY statement format.

'SORTLVL'
returns an empty string if the SAS table is not sorted. Otherwise, returns one of the following:

WEAK
The sort order of the SAS table is not validated. That is, the sort order was established by a user (for example, through a SORTEDBY SAS data set option). The system cannot validate its correctness, so the order of the rows cannot be depended upon.

STRONG
The sort order of the SAS table is validated. That is, the order of its rows can be depended upon. The sort order was established by the software (for example, through PROC SORT or through the OUT= option on the CONTENTS procedure).

'SORTSEQ'
returns an empty string if the SAS table is sorted on the native machine or if the sort collating sequence is the default for the operating system. Otherwise, returns the name of the alternate collating sequence that is used to sort the file.

'TYPE'
is the SAS table type.


Attributes for the ATTRN Function

To check for a numeric attribute, use ATTRN with one of the following values for attr-name:

'ANY'
specifies whether the table has rows or columns:
-1 The table has no rows or columns.
0 The table has no rows.
1 The table has both rows and columns.

'ALTERPW'
indicates whether a password is required in order to alter the SAS table:
1 The SAS table is alter protected.
0 The SAS table is not alter protected.

'ANOBS'
indicates whether the engine knows the number of rows:
1 The engine knows the correct number of rows.
0 The engine does not know the correct number of rows.

'ARAND'
indicates whether the engine supports random access:
1 The engine supports random access.
0 The engine does not support random access.

'ARWU'
indicates whether the engine can manipulate files:
1 The engine is not read-only. It can create or update SAS files.
0 The engine is read-only.

'CRDTE'
returns the SAS table creation date. The value returned is the internal SAS DATETIME value for the creation date. Use the DATETIME format to display this value.

'GENMAX'
returns the maximum number of generations.

'GENNEXT'
returns the next generation number to generate.

'ICONST'
returns information on the existence of integrity constraints for a SAS table:
0 No integrity constraints.
1 One or more general integrity constraints.
2 One or more referential integrity constraints.
3 Both one or more general integrity constraints and one or more referential integrity constraints.

'INDEX'
indicates whether the SAS table supports indexing:
1 Indexing is supported.
0 Indexing is not supported.

'ISINDEX'
indicates whether the SAS table is indexed:
1 At least one index exists for the SAS table.
0 The SAS table is not indexed.

'ISSUBSET'
indicates whether the SAS table is a subset:
1 At least one WHERE clause is active.
0 No WHERE clause is active.

'LRECL'
returns the logical record length.

'LRID'
returns the length of the record ID.

'MODTE'
returns the last date and time the SAS table was modified. Use the DATETIME format to display this value.

'NDEL'
returns the number of deleted rows in the SAS table.

'NLOBS'
returns the number of logical rows (those not marked for deletion). An active WHERE clause does not affect this number.

'NLOBSF'
returns the number of logical rows (those not marked for deletion) that match the active WHERE clause.

Note:   NLOBSF should be used with caution. Passing NLOBSF to ATTRN requires the engine to read every row from the table that matches the WHERE clause. Based on the file type and size, this can be a time-consuming process.  [cautionend]

'NOBS'
returns the number of physical rows (including those marked for deletion). An active WHERE clause does not affect this number.

'NVARS'
returns the number of columns in the SAS table.

'PW'
indicates whether a password is required in order to access the SAS table:
1 The SAS table is protected.
0 The SAS table is not protected.

'RADIX'
indicates whether access by row number is allowed:
1 Access by row number is allowed.
0 Access by row number is not allowed.
Note: A SAS table on a tape engine is index addressable even though it cannot be accessed by row number.

'READPW'
indicates whether a password is required in order to read the SAS table:
1 The SAS table is read protected.
0 The SAS table is not read protected.

'TAPE'
indicates whether the SAS table is a sequential tape file:
1 The SAS table is a sequential tape file.
0 The SAS table is not a sequential tape file.

'WHSTMT'
returns information about active WHERE clauses:
0 No WHERE clause is active.
1 A permanent WHERE clause is active.
2 A temporary WHERE clause is active.
3 Both permanent and temporary WHERE clauses are active.

'WRITEPW'
indicates whether a password is required in order to write to the SAS table:
1 The SAS table is write protected.
0 The SAS table is not write protected.


Examples

Example 1: Using the ATTRC Function

Ensure that the SAS table has been opened in UPDATE mode and display an error message if it is not open:

mode=attrc(tableid,'MODE');
if (mode ne 'U') then _msg_=
   'Table not open in UPDATE mode.';
else rc=sort(tableid,'name');

Example 2: Using the ATTRN Function

Determine whether a WHERE clause is currently active for a SAS table:

iswhere=attrn(tableid,'whstmt');
if (iswhere) then _msg_=
   'A WHERE clause is currently active.';

See Also

DESCRIBE

OPEN


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.