In SAS PROC SQL, you can dynamically create new variables and assign them names using the AS keyword. Once a variable has been created, the CALCULATED keyword in PROC SQL can be used to reference that newly computed value in subsequent calculations within the same query.
PROC SQL Example Using CALCULATED
For example, in the SQL code below, we create a new variable called NEW_WT and REV_WT, calculated as:
NEW_WT = WT * 0.5 REV_WT = NEW_WT * 6.5
The REV_WT column references the previously calculated NEW_WT value using the CALCULATED keyword.
OPTION NOCENTER;
OPTION SORTLIB='' ;
DATA IP1;
INFILE INDD ;
INPUT @01 DELIVERY_NR $CHAR10.
@12 WT 6.
;
PROC SQL ;
CREATE TABLE ALLDATA AS
SELECT DELIVERY_NR,WT,
(WT * 0.05) AS NEW_WT,
(CALCULATED NEW_WT * 6.5) AS REV_WT
FROM IP1
;
PROC PRINT DATA = ALLDATA;
Example Output
The resulting output will display both the NEWWT and REV_WT columns with proper headings.
The Output looks like:

When Should You Use the CALCULATED Keyword in PROC SQL?
The CALCULATED keyword in PROC SQL is especially useful when a calculated value needs to be reused multiple times within the same query. Without CALCULATED, you would need to repeat the entire expression each time it is required.
Related SAS Articles
You may also find these topics useful: