ATTRIB Statement

Associates a format, informat, label, and length with one or more variables.

Valid in: DATA step or PROC step
Categories: CAS
Information
Type: Declarative
Restriction: You cannot declare a VARCHAR variable with the ATTRIB statement.
UNIX specifics: Length specification
Windows specifics: Length specification
z/OS specifics: Length specification
See: ATTRIB Statement under Windows, UNIX, and z/OS

Syntax

UNIX:

ATTRIB variable-list-1 attribute-list-1 <...variable-list-n attribute-list-n>;

Windows:

ATTRIB variable-list-1 attribute-list-1<variable-list-n attribute-list-n>;

z/OS:

ATTRIB variable-list-1 attribute-list-1 <...variable-list-n attribute-list-n >;

Arguments

variable-list(s)

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

TipList 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.

Range For character variables, the range is from 1 to 32767 bytes for all operating environments.
Restrictions You cannot change the length of a variable using LENGTH= from PROC DATASETS.
You cannot declare a VARCHAR variable by using the ATTRIB statement.
Requirement Insert a dollar sign ($) in front of the length of character variables.
Operating environments For numeric variables, the minimum length that you can specify with the LENGTH= specification is 2 bytes in some operating environments and 3 bytes in other operating environments.
UNIX specifics The minimum length that you can specify for a numeric variable depends on the floating-point format used by your system. Because most systems use the IEEE floating-point format, the minimum is 3 bytes.
Windows specifics The length that you can specify for a numeric variable ranges from 3 to 8 bytes.
z/OS specifics Numeric variables can range from 2 to 8 bytes in length, and character variables can range from 1 to 32767 bytes in length.
Tip Use the ATTRIB statement to specify the length of variables in your output data set before you use a SET statement to bring the variables in from an existing data set.

TRANSCODE=YES | NO

specifies whether character variables can be transcoded. Use TRANSCODE=NO to suppress transcoding.

Default YES
Restriction The TRANSCODE=NO attribute is not supported by some SAS Workspace Server clients. Variables with TRANSCODE=NO are not returned in SAS 9.4. Prior to SAS 9.4, variables with TRANSCODE=NO are transcoded. Earlier releases of SAS cannot access a SAS 9.4 data set that contains a variable with a TRANSCODE=NO attribute.
Interactions You can use the “VTRANSCODE Function” and the VTRANSCODEX Function in SAS National Language Support (NLS): Reference Guide to return a value that indicates whether transcoding is turned on or off for a character variable.
If the TRANSCODE= attribute is set to NO for any character variable in a data set, PROC CONTENTS prints a transcode column that contains the TRANSCODE= value for each variable in the data set. If all character variables in the data set are specified as TRANSCODE=YES (the default), no transcode column is printed in the PROC CONTENTS output.
See Transcoding for NLS in SAS National Language Support (NLS): Reference Guide

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 that use the INFORMAT= option in the ATTRIB statement behave like informats that are used with modified list input.

Note: Modified list input uses format modifiers to help read in data. For example, use the : modifier with an informat to read character values that are longer than 8 bytes or that vary in length. For numeric values, you can use the : modifier to read nonstandard values.

Here is how SAS treats variables in modified list input.

  • uses the value of w in an informat to specify the length of previously undefined character variables
  • does not use the value of w in an informat to specify input field widths or column positions in an external file
  • ignores the value of w in numeric informats
  • uses the value of d in an informat in the same way SAS usually does for numeric informats
  • treats blanks that are embedded as input data as delimiters unless you change their status with the DLM= or DLMSTR= option specification in an INFILE statement

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 Statement or MERGE Statement

When you use the SET statement or MERGE statement to create a data set from several data sets, the TRANSCODE= values from the first data set read by the DATA step determine the TRANSCODE= values for the output data set. For example, in Using the MERGE Statement with Transcoded Variables the two input data sets, A and B, contain different TRANSCODE= attribute values for their shared variable, Var1. Input data set A’s value is NO and input data set B’s value is YES. When these two data sets are combined into the single output data set C, the TRANSCODE= attribute value for variable Var1 is NO because it equals the value in data set A (the first input data set read in the MERGE statement).

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 in an input data set or in an ATTRIB TRANSCODE= statement. If a SET statement or MERGE statement comes before an ATTRIB TRANSCODE= statement and the TRANSCODE= attribute contradicts the SET statement or MERGE statement, a warning occurs.

Comparisons

You can use either an ATTRIB statement or an individual attribute statement to change an attribute that is associated with a variable. For example, you can use either of these statements to change the following attributes: FORMAT, INFORMAT, LABEL, or LENGTH attributes.

Examples

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

Here are examples of ATTRIB statements that contain varying numbers of variables and attributes.

  • single variable and single attribute:
    attrib cost length=4;
  • single variable with multiple attributes:
    attrib saleday informat=mmddyy. 
    format=worddate.;
    
  • multiple variables with the same multiple attributes:
    attrib x y length=$4 label='TEST VARIABLE';
    
  • multiple variables with different multiple attributes:
    attrib x length=$4 label='TEST VARIABLE'
           y length=$2 label='RESPONSE';
    
  • variable list with single attribute:
    attrib month1-month12
           label='MONTHLY SALES';
    

Example 2: Using the SET Statement with Transcoded Variables

This example uses the SET statement. The TRANSCODE= attribute for Var1 in output data set C is NO because data set A is the first input data set read and Var1’s TRANSCODE= attribute in data set A is NO.

data A;
   length Var1 $4;
   Var1 = "rain";
   attrib Var1 transcode = no;
run;

data B;
   length Var1 $4;
   Var1 = "snow";
   attrib Var1 transcode = yes;
run;

data C;
   set A;
   set B;
   /* Check transcode setting for variable Var1 */
   rc1 = vtranscode(Var1);
   put rc1=;
run;

Example 3: Using the MERGE Statement with Transcoded Variables

This example uses the MERGE statement. The TRANSCODE= attribute for Var1 in output data set C is NO because data set A is the first input data set read in the MERGE statement, and Var1’s TRANSCODE= attribute in data set A is NO.

data A;
   length Var1 $4;
   Var1 = "rain";
   attrib Var1 transcode = no;
run;

data B;
   length Var1 $4;
   Var1 = "snow";
   attrib Var1 transcode = yes;
run;

data C;
   merge A B;
   /* Check transcode setting for variable Var1 */
   rc1 = vtranscode(Var1);
   put rc1=;
run;

See Also

Last updated: June 17, 2025