SAS Component Language Dictionary |
Category: | SAS Table |
Syntax |
attr-value=ATTRC(table-id,attr-name); |
attr-value=ATTRN(table-id,attr-name); |
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.
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.
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.
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:
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:
returns a string indicating the type of file:
local files.
non-native files.
returns 'YES' or 'NO' depending on whether the SAS table is encrypted.
returns the name of the engine used to access the SAS table.
returns the libref of the SAS data library in which the SAS table resides.
returns the mode in which the SAS table was opened, such as:
For more information about open modes, see OPEN.
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.
returns an empty string if the SAS table is not sorted. Otherwise, returns one of the following:
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.
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).
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.
Attributes for the ATTRN Function |
To check for a numeric attribute, use ATTRN with one of the following values for attr-name:
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. |
indicates whether a password is required in order to alter the SAS table:
1 | |
0 |
indicates whether the engine knows the number of rows:
1 | |
0 |
indicates whether the engine supports random access:
1 | |
0 |
indicates whether the engine can manipulate files:
1 |
The engine is not read-only. It can create or update SAS files. |
0 |
indicates whether an audit trail is active:
1 |
An audit trail is active. |
0 |
No audit trail is active. |
indicates whether the audit trail will log an image of the row before updates:
1 |
The audit trail will log an image of the row before updates. |
0 |
No image of the row will be logged before updates. |
indicates whether the audit trail will log an image of the row after updates:
1 |
The audit trail will log an image of the row after updates. |
0 |
No image of the row will be logged after updates. |
indicates whether the audit trail will log an image of an unsuccessful update to the row:
1 |
The audit trail will log an image of an unsuccessful update to the row. |
0 |
No image of an unsuccessful update to the row will be logged. |
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.
returns information on the existence of integrity constraints for a SAS table:
0 | |
1 | |
2 | |
3 |
Both one or more general integrity constraints and one or more referential integrity constraints. |
indicates whether the SAS table supports indexing:
1 | |
0 |
indicates whether the SAS table is indexed:
1 | |
0 |
indicates whether the SAS table is a subset:
1 | |
0 |
returns the last date and time the SAS table was modified. Use the DATETIME format to display this value.
returns the number of logical rows (those not marked for deletion). An active WHERE clause does not affect this number.
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.
returns the number of physical rows (including those marked for deletion). An active WHERE clause does not affect this number.
indicates whether a password is required in order to access the SAS table:
1 | |
0 |
indicates whether access by row number is allowed:
1 | |
0 |
indicates whether a password is required in order to read the SAS table:
1 | |
0 |
indicates whether the SAS table is a sequential tape file:
1 | |
0 |
returns information about active WHERE clauses:
0 | |
1 | |
2 | |
3 |
indicates whether a password is required in order to write to the SAS table:
1 | |
0 |
Examples |
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');
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.';
To test the AUDIT attributes of the ATTRN function, follow these steps:
Create a data set with an audit file by entering the following code in the SAS Editor and then submitting it:
data sasuser.class; set sashelp.class; run; proc datasets lib=sasuser; audit class; initiate; log data_image=yes error_image=no before_image=yes; run;quit;
Query the audit file by entering the following code in an SCL file:
INIT: dsid=open('sasuser.class'); auditIsActive=attrn(dsid,'AUDIT'); auditHasDataImage=attrn(dsid,'AUDIT_DATA'); auditHasErrorImage=attrn(dsid,'AUDIT_ERROR'); auditHasBeforeImage=attrn(dsid,'AUDIT_BEFORE'); put auditIsActive= auditHasDataImage= auditHasErrorImage= auditHasBeforeImage=; return;
When you compile and then execute the SCL code, the SAS log displays:
auditIsActive=1 auditHasDataImage=1 auditHasErrorImage=0 auditHasBeforeImage=1;
See Also |
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.