Modifying All Observations in a SAS Data Set

Overview

When every observation in a SAS data set requires the same modification, you can use the MODIFY statement and specify the modification using an assignment statement.
General form, MODIFY statement with an assignment statement:
DATA SAS-data-set;
MODIFY SAS-data-set;
existing-variable = expression;
RUN;
Here is an explanation of the syntax:
SAS-data-set
is the name of the SAS data set that you want to modify.
existing-variable
is the name of the variable whose values you want to update.
expression
is a function or other expression that you want to apply to the variable.

Example

Suppose an airline has decided to give passengers more leg room. The airline must decrease the number of seats in the business and economy classes. The SAS data set Capacity has the variables CapEcon and CapBusiness that hold values for the number of seats in the economy and business classes.
In the program below, the assignment statement for CapEcon reduces the number of seats in the economy class to 95% of the original number, and the assignment statement for CapBusiness reduces the number of seats in the business class to 90% of the original number. The INT function is used in both assignment statements to return the integer portion of the result.
Note: If you choose to run this example, you must copy the data set Capacity from the Sasuser library to the Work library.
proc print data=capacity (obs=4);
run;

data capacity;
   modify capacity;
   CapEcon = int(CapEcon * .95);
   CapBusiness = int(CapBusiness * .90);
run;

proc print data=capacity (obs=4);
run;
The following output shows the data before the MODIFY statement.
output before the modify statement
The following output shows the data after the MODIFY statement. You can see that the values in CapBusiness and CapEcon have been reduced.
output after the modify statement
..................Content has been hidden....................

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