Strings (PRINT command)
You can specify string values within the variable list. Strings must be enclosed in quotes.
- If a format is specified for a variable list, the application of the format is interrupted by a specified string. Thus, the string has the same effect within a variable list as an asterisk.
- Strings can be used to create column headings for
the displayed variables. The
PRINT
command that specifies the column headings must be used within aDO IF-END IF
structure. If you want the column headings to begin a new page in the output, use aPRINT EJECT
command (rather thanPRINT
) to specify the headings (seePRINT EJECT
).
Including Strings in the Output
PRINT / NAME 'HIRED=' MOHIRED(F2) '/' YRHIRED
' SALARY=' SALARY (DOLLAR8).
EXECUTE.
- Three strings are specified. The strings
HIRED=
andSALARY=
label the values being displayed. The slash that is specified between MOHIRED and YRHIRED creates a composite hiring date. TheF2
format is supplied for variable MOHIRED in order to suppress the blank that would follow it if the dictionary format were used. - NAME and YRHIRED are displayed with default formats.
The
'HIRED='
specification prevents theF2
format from applying to NAME, and the'SALARY='
specification prevents theDOLLAR8
format from applying to YRHIRED.
Setting Up Column Headers
DO IF $CASENUM EQ 1.
PRINT /' NAME ' 1 'DEPT' 25 'HIRED' 30 ' SALARY' 35.
END IF.
PRINT / NAME DEPT *
MOHIRED 30-31 '/' YRHIRED *
SALARY 35-42(DOLLAR).
EXECUTE.
- The first
PRINT
command specifies strings only. The integer after each string specifies the beginning column number of the string. The strings will be used as column headings for the variables.DO IF $CASENUM EQ 1
causes the firstPRINT
command to be executed only once, as the first case is processed.END IF
closes the structure. - The second
PRINT
command specifies the variables to be displayed. This command is executed once for each case in the data. Column locations are specified to align the values with the column headings. In this example, theT
format element could also have been used to align the variables and the column headings. For example,MOHIRED (T30,F2)
begins the display of values for variable MOHIRED in column 30. - The asterisk after DEPT prevents the format that is specified for MOHIRED from applying to NAME and DEPT. The asterisk after YRHIRED prevents the format that is specified for SALARY from applying to YRHIRED.