Improving Program Efficiency with Macro Variables |
Creating Macro Variables During DATA Step
Execution![]() ![]() |
In this lesson so far, you have used the
The
For example, suppose you need to create a data set that contains the total
number of overtime hours worked by temporary employees. The DATA step you
write calculates total overtime hours, but how do you create a macro variable
to hold this value? You cannot use a
You can use the CALL SYMPUT routine to create a macro variable whose value is assigned during the execution of the DATA step. To learn how to use this routine, let's look more closely at your DATA step. The DATA step below creates the new data set Hrd.Overtime and uses the subsetting IF statement to include only the names of employees who worked overtime hours. It also calculates the total number of overtime hours. |
data hrd.overtime; set hrd.temp(keep=name overtime); if overtime ne .; TotalOvertime+overtime; run; proc print data=hrd.overtime; run; Before submitting the program, you decide to add a title displaying the total number of overtime hours worked by temporary employees. So, you add a TITLE statement containing a macro variable reference to substitute the total number of hours into the title. |
title "Temporary Employees Worked &total OT Hours"; |
To create the macro variable total , you must use the CALL
SYMPUT routine. The CALL SYMPUT routine enables you to assign a value that
is produced in the DATA step to a macro variable. The CALL SYMPUT routine
is a CALL routine, which is a program you can run from the DATA step. Like
all CALL routines, the CALL SYMPUT routine must be invoked by means of a
CALL statement. |
General form, CALL statement for CALL SYMPUT routine:
where
|
![]() ![]() ![]() ![]() ![]() ![]() |
|
![]() |
![]() |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.