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 |
Table of Contents
names the variables that you want to associate with the attributes.
specifies one or more attributes to assign to variable-list. Specify one or more of these attributes in the ATTRIB statement:
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. |
|---|
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. |
|---|
associates a label with variables in variable-list.
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. |
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 |
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.
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.
Here is how SAS treats variables in modified list input.
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.
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.
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.
Here are examples of ATTRIB statements that contain varying numbers of variables and attributes.
attrib cost length=4;
attrib saleday informat=mmddyy.
format=worddate.;
attrib x y length=$4 label='TEST VARIABLE';
attrib x length=$4 label='TEST VARIABLE'
y length=$2 label='RESPONSE';
attrib month1-month12
label='MONTHLY SALES';
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;
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;