Previous Page | Next Page

Statements

ATTRIB Statement



Associates a format, informat, label, and length with one or more variables.
Valid: in a DATA step
Category: Information
Type: Declarative
See: ATTRIB Statement under Windows UNIX OpenVMS z/OS

Syntax
Arguments
Details
The Basics
How SAS Treats Variables When You Assign Informats with the INFORMAT= Option in the ATTRIB Statement
How SAS Treats Transcoded Variables When You Use the SET and MERGE Statements
Comparisons
Examples
Example 1: Examples of ATTRIB Statements with Varying Numbers of Variables and Attributes
Example 2: Using the SET Statement with Transcoded Variables
Example 3: Using the MERGE Statement with Transcoded Variables
See Also

Syntax

ATTRIB variable-list(s) attribute-list(s) ;


Arguments

variable-list(s)

names the variables that you want to associate with the attributes.

Tip: List the variables in any form that SAS allows.
attribute-list(s)

specifies one or more attributes to assign to variable-list. Specify one or more of these attributes in the ATTRIB statement:

FORMAT=format

associates a format with variables in variable-list.

Tip: The format can be either a standard SAS format or a format that is defined with the FORMAT procedure.
INFORMAT=informat

associates an informat with variables in variable-list.

Tip: The informat can be either a standard SAS informat or an informat that is defined with the FORMAT procedure.
LABEL='label'

associates a label with variables in variable-list.

LENGTH=<$>length

specifies the length of variables in variable-list.

Requirement: Put a dollar sign ($) in front of the length of character variables.
Tip: Use the ATTRIB statement before the SET statement to change the length of variables in an output data set when you use an existing data set as input.
Range: For character variables, the range is 1 to 32,767 for all operating environments.

Operating Environment Information:   For numeric variables, the minimum length you can specify with the LENGTH= specification is 2 in some operating environments and 3 in others.  [cautionend]

Restriction: You cannot change the length of a variable using LENGTH= from PROC DATASETS.
TRANSCODE=YES | NO

specifies whether character variables can be transcoded. Use TRANSCODE=NO to suppress transcoding. For more information about transcoding, see Transcoding in the SAS National Language Support (NLS): Reference Guide.

Default: YES
Restriction: The TRANSCODE=NO attribute is not supported by some SAS Workspace Server clients. In SAS 9.2, if the attribute is not supported, variable values with TRANSCODE=NO are replaced (masked) with asterisks (*). Before SAS 9.2, variables with TRANSCODE=NO were transcoded.
Restriction: Prior releases of SAS cannot access a SAS 9.1 data set that contains a variable with a TRANSCODE=NO attribute.
Restriction: Transcode suppression is not supported by the V6TAPE engine.
Interaction: You can use the VTRANSCODE and VTRANSCODEX functions to return a value that indicates whether transcoding is on or off for a character variable.
Interaction: If the TRANSCODE= attribute is set to NO for any character variable in a data set, then PROC CONTENTS prints a transcode column that contains the TRANSCODE= value for each variable in the data set. If all variables in the data set are set to the default TRANSCODE= value (YES), then no transcode column prints.

Details


The Basics

Using the ATTRIB statement in the DATA step permanently associates attributes with variables by changing the descriptor information of the SAS data set that contains the variables.

You can use ATTRIB in a PROC step, but the rules are different.


How SAS Treats Variables When You Assign Informats with the INFORMAT= Option in the ATTRIB Statement

Informats that are associated with variables by using the INFORMAT= option in the ATTRIB statement behave like informats that are used with modified list input. SAS reads the variables by using the scanning feature of list input, but applies the informat. In modified list input, SAS

If you have coded the INPUT statement to use another style of input, such as formatted input or column input, that style of input is not used when you use the INFORMAT= option in the ATTRIB statement.


How SAS Treats Transcoded Variables When You Use the SET and MERGE Statements

When you use the SET or MERGE statement to create a data set from several data sets, SAS makes the TRANSCODE= attribute of the variable in the output data set equal to the TRANSCODE= value of the variable in the first data set. See Using the SET Statement with Transcoded Variables and Using the MERGE Statement with Transcoded Variables.

Note:   The TRANSCODE= attribute is set when the variable is first seen on an input data set or in an ATTRIB TRANSCODE= statement. If a SET or MERGE statement comes before an ATTRIB TRANSCODE= statement and the TRANSCODE= attribute contradicts the SET statement, a warning will occur.  [cautionend]


Comparisons

You can use either an ATTRIB statement or an individual attribute statement such as FORMAT, INFORMAT, LABEL, and LENGTH to change an attribute that is associated with a variable.


Examples


Example 1: Examples of ATTRIB Statements with Varying Numbers of Variables and Attributes

Here are examples of ATTRIB statements that contain different numbers of variables and attributes:


Example 2: Using the SET Statement with Transcoded Variables

In this example, which uses the SET statement, the variable Z's TRANSCODE= attribute in data set A is NO because B is the first data set and Z's TRANSCODE= attribute in data set B is NO.

data b;
   length z $4;
   z = 'ice';
   attrib z transcode = no;
data c;
   length z $4;
   z = 'snow';
   attrib z transcode = yes;
data a;
   set b;
   set c;
   /* Check transcode setting for variable Z */
   rc1 = vtranscode(z);
   put rc1=;
run;


Example 3: Using the MERGE Statement with Transcoded Variables

In this example, which uses the MERGE statement, the variable Z's TRANSCODE= attribute in data set A is YES because C is the first data set and Z's TRANSCODE= attribute in data set C is YES.

data b;
   length z $4;
   z = 'ice';
   attrib z transcode = no;
data c;
   length z $4;
   z = 'snow';
   attrib z transcode = yes;
data a;
   merge c b;
   /* Check transcode setting for variable Z */
   rc1 = vtranscode(z);
   put rc1=;
run;


See Also

Statements:

FORMAT Statement

INFORMAT Statement

LABEL Statement

LENGTH Statement

Functions:

VTRANSCODE in the SAS National Language Support (NLS): Reference Guide

VTRANSCODEX in the SAS National Language Support (NLS): Reference Guide

Previous Page | Next Page | Top of Page