Hans Van Den Steen wrote:
Is it possible to create a new string variable that contains the valueHans,
labels of an existing numeric variable.Example: I want to make a concatenation of a string variable x1 and the
"description" (value label) of a numeric variable x2.Thanks
To do this yourself:
Open a script:
Help>SPSS Objects:
Click SPSSInfo from the treeview (bottom left)
Click Properties
Double Click ValueLabelAt
Click Example:
You will see a script which extracts value labels from a variable and places them into an array.
Slice and Dice once you know what to chop out.
(Notice I have added two inputboxes. I haven't cached any variables
and have removed the array)
If you are not running 7.5 then the options are pretty limited.
Best I can think of
is run REPORT with LABELS and an OUTFILE. Parse the output and
merge
with your data.
Regards, David
Open this in a script window.
Open your data file.
Run the script.
Sub Main
Dim objSpssInfo As ISpssInfo
Dim strVarName As String
Dim strNewVarName As String
Dim lngLength As Long
'One way to get user input
strVarName=InputBox("Please enter your Numeric variable name")
strNewVarName=InputBox("Please enter your String variable name")
'Find the right variable
Set objSpssInfo = objSpssApp.SpssInfo
Dim I As Integer
For I = 0 To objSpssInfo.NumVariables - 1
If objSpssInfo.VariableAt(I)=strVarName Then
& nbsp; Exit For
End If
Next I
'Build syntax to create the string variable with value labels
Dim StrSPSSSyntax As String
StrSPSSSyntax="STRING " & strNewVarName & "(A60)." & vbCrLf
Dim J As Integer
For J = 0 To objSpssInfo.NumberOfValueLabels(I) -1
'If oldvar = value newvar=value label.....
StrSPSSSyntax= StrSPSSSyntax & "IF " & strVarName & "=" & objSpssInfo.ValueAt (I, J) & _
strNewVarName & " = " & Chr$(34) & objSpssInfo.ValueLabelAt (I, J) & Chr$(34) & "." & vbCrLf
Next J
StrSPSSSyntax= StrSPSSSyntax & "EXECUTE."
'Submit the commands
objSpssApp.ExecuteCommands(StrSPSSSyntax,False)
End Sub