Specifying a New Variable in an ATTRIB Statement
The ATTRIB statement enables you to specify one or more of the following variable
attributes for an existing variable:
FORMAT=
INFORMAT=
LABEL=
LENGTH=
If the variable does not already exist, one or more of the FORMAT=, INFORMAT=, and
LENGTH= attributes can be used to create a new variable. For example, the following
DATA step creates a variable named FLAVOR in a data set named Lollipops:
data lollipops;
Flavor="Cherry";
attrib Flavor format=$10.;
run;
Note: You cannot create a new variable by using a LABEL statement or the ATTRIB
statement's LABEL= attribute by itself. Labels can be applied only to existing
variables.
For more information, see “ATTRIB Statement” in SAS Statements: Reference.
Using the IN= Data Set Option
The IN= data set option creates a special Boolean variable that indicates whether the
data set contributed data to the current observation. The variable has a value of 1 when
true, and a value of 0 when false. You can use IN= on the SET, MERGE, and UPDATE
statements in a DATA step.
The following example shows a merge of the Old and New data sets where the IN=
option is used to create a variable named X that indicates whether the New data set
contributed data to the observation:
data master missing;
merge old new(in=x);
by id;
if x=0 then output missing;
else output master;
run;
Variable Type Conversions
If you define a numeric variable and assign the result of a character expression to it, SAS
tries to convert the character result of the expression to a numeric value and to execute
the statement. If the conversion is not possible, SAS prints a note to the log, assigns the
numeric variable a value of missing, and sets the automatic variable _ERROR_ to 1. For
a listing of the rules by which SAS automatically converts character variables to numeric
variables and vice versa, see “Automatic Numeric-Character Conversion” on page 98.
44 Chapter 4 SAS Variables
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.137.59