' Define a macro which will give the variable label of a variable ' Raynald Levesque 2000/06/21 rlevesque@videotron.ca ' Requirements : data file must be in the data editor ' Results : for each variable whose name has 7 or less characters, a macro is ' created whose Name Is ! plus the Name of the variable (For instance ' for variable named qtop1 the macro Name Is !qtop1) ' Executing the macro !qtop1 produces the Variable label of qtop1. ' Instuctions : Run this script first, then add the following line at the beginning of your ' syntax (changing path as required) ' INCLUDE "c:\\temp\\variable label macro.sps" ' This is useful to print variable label instead of variable name in ' the heading of tables Or graphs. This script is useful for instance when you ' want to print the variable labels in the title of a Table or Graph. 'Possible improvements: for variable name having 8 chars, the script could replace the first 'or last characters (at the user's choice by !) Option Explicit Sub Main Dim objSPSSInfo As ISpssInfo,ValueLabels() Dim NumVars As Long,I As Long,J As Long, VarName As String, VarLabel As String Set objSPSSInfo = objSpssApp.SpssInfo NumVars=objSPSSInfo.NumVariables-1 Open "c:\\temp\\variable label macro.sps" For Output As #1 For I=0 To NumVars VarName= objSPSSInfo.VariableAt(I) If Len(VarName)<8 Then VarLabel= objSPSSInfo.VariableLabelAt(I) If Len(varlabel)=0 Then varlabel=varname End If Print #1, "DEFINE !" & Varname & "() " & VarLabel & " !ENDDEFINE." End If Next I Close #1 End Sub