|
Is there a way to program SPSS to take all of the variable names from a given data file (.sav) and automatically populate a syntax file with those names? They would need to be fed in as variables into a macro.
Also, to just try and make it a little more difficult, can this be done in V12?
Thank you.
Zachary |
|
Zachary Feinstein wrote:
> Is there a way to program SPSS to take all of the variable names from > a given data file (.sav) and automatically populate a syntax file with > those names? They would need to be fed in as variables into a macro. > > Also, to just try and make it a little more difficult, can this be > done in V12? > > Hi Zachary: Can you be a bit more specific? In order to help you, I need a more information.Using SPSS 12 will be indeed a handicap, because any solution involving multiple datasets (nor Python) will be not possible. A) First idea: have you tried the keyword ALL? FREQ VAR=ALL. Will give you frequency tables for every variable in the dataset. B) You can use the keyword TO to indicate a list of variables like this: Firstvar TO LastVar. FREQ VAR=Firstvar TO LastVar. Will give you frequency tables for every variable from FirstVar to LastVar. C) In case your macro needs a full list to process, like in, for example," !DO !I !IN (!list) ", here's another solution: 1) Save your original data 2) FLIP the entire dataset 3) Get rid of all variables in the transposed dataset, with the exception of CASE_LBL, the one that keeps the names of all the variables. 4) Write to disk a syntax file (using WRITE) with the commands. See this example (written without testing, might need some debugging): DO IF $CASENUM EQ 1. - WRITE OUTFILE 'C:\temp\MacroCall.sps' /'MYMACRO list='. END IF. WRITE OUTFILE 'C:\temp\MacroCall.sps'/' ' CASE_LBL. CACHE. EXE. 5) Get the original dataset 6) run the syntax file using INCLUDE 'C:\temp\MacroCall.sps' I'll be able to provide better help if you explain what you want to achieve in more detail. HTH, Marta GG -- For miscellaneous SPSS related statistical stuff, visit: http://gjyp.nl/marta/ ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
In reply to this post by Zachary Feinstein
Hi Zachary,
Copy this script into a new script (File-New-Script) and press Ctrl+F5. Sub Main Dim DataDoc As ISpssDataDoc Dim SyntDoc As ISpssSyntaxDoc Dim objSPSSInfo As ISpssInfo,ValueLabels() Dim i, NumVars As Long Dim ss As String Set objSPSSInfo = objSpssApp.SpssInfo Set DataDoc = objSpssApp.Documents.GetDataDoc(0) NumVars=objSPSSInfo.NumVariables-1 ss = "" For i=0 To NumVars ss = ss & objSPSSInfo.VariableAt(i) & vbTab & objSPSSInfo.VariableLabelAt(i) & vbCrLf Next i Set SyntDoc = objSpssApp.NewSyntaxDoc SyntDoc.Visible = True SyntDoc.Text = ss End Sub If you don't want to inlude Variable Labels change thi line: ss = ss & objSPSSInfo.VariableAt(i) & vbTab & objSPSSInfo.VariableLabelAt(i) & vbCrLf to ss = ss & objSPSSInfo.VariableAt(i) & vbCrLf Hope this solves your problem. All the best \WL 2009/8/27 Zachary Feinstein <[hidden email]>
-- Wilhelm Landerholm Queue/STATB BOX 92 162 12 Vallingby Sweden +46-735-460000 http://www.qsweden.com http://www.statb.com QUEUE - your partner in data analysis, data modeling and data mining. STATB - your Research agency. |
| Free forum by Nabble | Edit this page |
