程序代写代做代考 Modifying Variable

Modifying Variable
Attributes
in
SAS
STAT 342 – Fall 2020 Tutorial – 12


Understanding How to Modify Variable Attributes
Attributes of a variable in a SAS dataset,
• Name
• Type
• Length
• Format
• Informat
• Label etc.
The DATASET procedure along with MODIFY statement allows us to change “CERTAIN” attributes of variables
Can modify: Name (rename), Format, Labels (since these are variable attributes) Cannot modify: Type, length (since these are fixed attributes)

• •

Renaming Variables
• Renaming is mostly used prior to combining datasets (merging etc.)
• CanrenamewithProcDATASETSprocedurealongwithMODIFY
MODIFY SAS-data-set;
RENAME old-name=new-name;

Changing and Removing Formats
• With Proc Datasets procedure we can change or remove the existing format of a variable
• Change:
MODIFY SAS-data-set;
FORMAT variable-name=;
• Remove:
MODIFY SAS-data-set;
FORMAT variable-name; /*List the variable name only to remove format*/

Changing and Removing Labels
• With Proc Datasets procedure we can change or remove the existing labels of a variable
• Change:
MODIFY SAS-data-set;
LABEL variable-name=‘label’;
• Remove:
MODIFY SAS-data-set;
LABEL variable-name=‘ ‘;

Automatic Variable ( _n_ ) in SAS
• When you open a SAS data file in a data library, you will notice the observations are numbered at the first column.
• The automatic variable _n_ represents the observation numbers.
• This variable hidden in the DATA step is simple yet powerful in programming practice.

Example: use of _n_ with two dimensional
arrays
Exposure to Benzene
Benzene Level
? ?
? ? ?