How to get current variable from excel into SPSS - spss

I'm new in the SPSS and I need some help.I have a Excel file with many columns and I have to write syntax to get only the variables which I need (for example id name). The name of the variables are at first row.

First import your excel file (use the open data menu and paste the syntax).
then use this:
add files /file=* /keep= var1 var2 var3.
This will let you keep only the variables you need and in the preferred order.
if some of these variables are ordered consecutively in the file you can use "someVar TO someotherVar" in the keep subcommand.

Related

How to create a file with two entries in COBOL?

I have two files, the first one has the date and the second one has multiple registers.
I want to create something like this:
Input File 1:
20200509
Input File 2:
0000001
0000002
0000003
Output
202005090000001
202005090000002
202005090000003
Thank u.
Build a record of two fields. I will not give you picture clauses.
Read file one and populate field one. (end of field one stuff).
Read file two and for each record, populate field two and write an output record.
Field one never changes?
Look into JOINKEYS (FILL?) if you get a moment and your shop has it.
And the record in File one should probably be a parameter.
Yes you will need to open and close the files, use filestat, and understand what a priming read is.
If you don't mind bad style and ANS COBOL c. 1972 see
https://github.com/mckenzm/join2files/blob/main/stackex1.cbl
(No filestat, no exception (empty file) handling.)

ztree loaded table: How to match variables

I am trying to match data in an experiment, created through individual input, to a payoff structure that is stored in a txt I have (successfully) loaded into zTree before.
However, I do not know, how to find the - in specific - payoff to the corresponding input in the txt file that is defined there.
The txt file looks as follows:
NK table screenshot
Within the game, the "Input" variable is generated by users and now the payoff needs to be found corresponding to the input generated. Can anyone help out here?
Thanks a lot in advance!
TABLENAME.find(condition, variable) function retrieves the first value that fits a condition.
Assuming the user has the variable MyInput in the subjects table, this program running on subjects would do the trick:
NKtable.find(Input == :MyInput, Payoff)

Saving a list of variables in a file

I'd like to automate the syntax. The number of variables varies from year to year. In one year the variable state occurs four times, in the next maybe six times.
I'd like to use something like WRITE OUTFILE to store a list containing the variable names and which I can call whenever needed.
Not sure how you can get a few variables called "state" in the same dataset?
In any case, if you want a list of the variables in your data saved as a new file, you can do this:
dataset declare ListOfVars.
oms /select tables /if commands=['File Information'] subtypes=['Variable Information']
/destination format=sav outfile='ListOfVars' .
display dictionary.
omsend.
dataset activate ListOfVars.
The new dataset ListOfVars has the list of your variables and their labels (and some other data).
Now just save the table to a new fine and keep whatever variables you need from it.

How can I export SPSS custom tables to a specific Excel sheet without the SPSS?

I want to put different custom tables to different sheets in Excel. I tried with OMS and OUTPUT EXPORT but that functions not do what I want. If somebody have idea I hope that will help me. :)
OUTPUT EXPORT has an OPERATION subcommand with options CREATEFILE / CREATESHEET / MODIFYSHEET from which you can route CTABLES to desired sheets in a target/new Excel file.
You'll need to organise your OUTPUT documents as you wish your sheets.
Exorting to Excel using OMS you can not route to a specific sheet only with OUTPUT EXPORT you can.
OUTPUT EXPORT can write different sheets, but it doesn't give you much flexibiity in the objects that get exported when using it via syntax. The syntax mode assumes that you are not going to be interactively selecting the tables.
However, the SPSSINC OUTPUT MODIFY extension command includes a customoutputfunctions.py module that has an excelexport function that will do what you want. Here is an example. For more information see the SPSSINC OUTPUT MODIFY documentation or the dialog (on Utilities once installed). Then look at the examples in the customoutputfunctions.py module.
SPSSINC MODIFY OUTPUT TABLES
/IF SUBTYPE="'Custom Table'" PROCESS=ALL
/CUSTOM FUNCTION="customoutputfunctions.excelexport(file='c:/temp/extest.xls',
sheet='table#',action='CreateWorksheet')".

Syntax to extract variable labels from SPSS file

I have hundreds of SPSS .sav files. For each one I want to extract the variable NAMES and variable LABELS as a two column table to a csv file. I know that this is straightforward by simply copying and pasting from the "Variable view" window, but I would really like to know how to do this using syntax. Is this possible?
Many thanks in advance for any help!
You might be interested in the GATHERMD extension command, It takes a wildcard for the file names and builds a dataset with three variables: the file name, the variable name, and the variable label. You could then just save that as a csv file.
This command requires the Python Essentials available with your Statistics installation or via the SPSS Community website (www.ibm.com/developerworks/spssdevcentral).
Using native Statistics syntax, DISPLAY DICTIONARY and CODEBOOK might be helpful, but they won't give you all this information in one table.

Resources