Improving Program Efficiency with Macro Variables |
Creating Macro Variables During DATA Step
Execution![]() ![]() |
To create a macro variable total that will contain the total
overtime hours, you write the CALL SYMPUT routine as follows: |
call symput('total',totalovertime); |
This routine creates the macro variable total by assigning
it the value of the DATA set variable TotalOvertime , which is calculated
during DATA step execution. If the data set variable is numeric, the numeric
values are automatically converted to character values as the values are
assigned to the macro variable. A message appears in the SAS log indicating
that this automatic conversion has taken place.
Then you add this CALL SYMPUT routine to your DATA step and submit the program. |
data hrd.overtime; set hrd.temp(keep=name overtime); if overtime ne .; TotalOvertime+overtime; call symput('total',totalovertime); run; title "Temporary Employees Worked &total OT Hours"; proc print data=hrd.overtime; run; |
Checking the output below, you see that the macro variable value appears in the title. However, notice that the macro variable value is preceded by a number of blanks. |
![]() |
The blanks appear in SAS listing output, which is the type of output you see in the Output window. The blanks do not appear in HTML output. |
|<-spaces->| | |||||||||||||||||||||||||||||||||||||
|
The leading blanks result from the automatic numeric-to-character conversion
that occurs when the numeric value of TotalOvertime is assigned to
the macro variable total . The default format used for this
conversion creates the leading blanks.
This conversion also writes messages to the SAS log. |
SAS Log
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 55:24 |
You can remove the leading blanks and avoid the conversion messages by
explicitly converting the numeric values of TotalOvertime to character
by using the PUT function. You write the CALL SYMPUT routine and include
the PUT function as follows: |
call symput('total',put(totalovertime,2.)); |
For more information on the PUT function, refer to the lesson
Transforming Data with SAS Functions.
After adding the newly written CALL SYMPUT routine to your DATA step and submitting the program, your output appears as expected. |
no extra spaces->||<- | |||||||||||||||||||||||||||||||||||||
|
![]() ![]() ![]() ![]() ![]() ![]() |
|
![]() |
![]() |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.