在 SPSS 中生成语法的语法 [英] Syntax to generate a Syntax in SPSS
问题描述
我正在尝试构建一个语法来在 SPSS 中生成一个语法,但我遇到了一些问题......我有一个带有元数据的 excel 文件,我想用它来制作一种语法来从中提取信息(像这样,如果我有一个巨大的数据库,我只需要保持 excel 的更新——添加/删除变量,等 - 然后运行语法以提取新语法所需的信息).我还注意到生成的语法总是在 15Mb 左右,这是很多(应用于 500 多行)!由于在不同的计算机和/或配置中运行语法,我不使用 Python.有任何想法吗?谁能帮帮我吗?提前致谢.
I’m trying to construct a Syntax to generate a Syntax in SPSS, but I’m having some issues… I have an excel file with metadata and I would like to use it in order to make a syntax to extract information from it (like this, if I have a huge database, I just need to keep the excel updated – add/delete variables, etc. - and then run a syntax to extract the needed information for a new syntax). I also noticed the produced syntax has always around 15Mb, which is a lot (applied to more than 500 lines)! I don’t use Python due to run syntax in different computers and/or configurations. Any ideas? Can anyone please help me? Thank you in advance.
示例:
(test.xlsx – 表 1)
Var 代码标签列表 Var_label(连接 Var+Label)
V1 3 Sex 1 V1 Sex"
V2 1 作品 2 V2 作品"
V3 3 国家 3 V3 国家"
V4 1 已婚 2 V4 已婚"
V5 1 儿童 2 V5 儿童"
V6 2 Satisf1 4 V6 Satisf1"
V7 2 Satisf2 4 V7 Satisf2"
Example:
(test.xlsx – sheet 1)
Var Code Label List Var_label (concatenate Var+Label)
V1 3 Sex 1 V1 "Sex"
V2 1 Work 2 V2 "Work"
V3 3 Country 3 V3 "Country"
V4 1 Married 2 V4 "Married"
V5 1 Kids 2 V5 "Kids"
V6 2 Satisf1 4 V6 "Satisf1"
V7 2 Satisf2 4 V7 "Satisf2"
(来自其他文件的信息)
列表 = 1
1个男"
2 女"
列表 = 2
1 是"
2 不"
列表 = 3
1个欧洲"
2 美国"
3 亚洲"
4 非洲"
5 大洋洲"
列表 = 4
1非常不满意"
10个非常满意"
(information from other file)
List = 1
1 "Male"
2 "Female"
List = 2
1 "Yes"
2 "No"
List = 3
1 "Europe"
2 "America"
3 "Asia"
4 "Africa"
5 "Oceania"
List = 4
1 "Very unsatisfied"
10 "Very satisfied"
我想创建一个语法来生成新的语法来应用VARIABLE LABELS"和VALUE LABELS".所以,我想到了这样的事情:
I want to make a Syntax that generates a new syntax to apply "VARIABLE LABELS" and "VALUE LABELS". So, I thought about something like this:
GET DATA
/TYPE=XLSX
/FILE="test.xlsx"
/SHEET=name 'sheet 1'
/CELLRANGE=FULL
/READNAMES=ON
/DATATYPEMIN PERCENTAGE=95.0.
EXECUTE.
STRING vlb (A15) labels (A150) value (A12) lab (A1500) point (A2) separate (A50) space (A2) list1 (A100) list2 (A100).
SELECT IF (Code=1).
COMPUTE vlb = "VARIABLE LABELS".
COMPUTE labels = CONCAT (RTRIM(Var_label)," ").
COMPUTE point = ".".
COMPUTE value = "VALUE LABELS".
COMPUTE lab = CONCAT (RTRIM(Var)," ").
COMPUTE list1 = '1 " Yes "'.
COMPUTE list2 = '2 "No".'.
COMPUTE space = " ".
COMPUTE separate="************************************************.".
WRITE OUTFILE = "list_01.sps" / vlb.
WRITE OUTFILE = "list_01.sps" /labels.
WRITE OUTFILE = "list_01.sps" /point.
WRITE OUTFILE = "list_01.sps" /value.
WRITE OUTFILE = "list_01.sps" /lab.
WRITE OUTFILE = "list_01.sps" /list1.
WRITE OUTFILE = "list_01.sps" /list2.
WRITE OUTFILE = "list_01.sps" /space.
WRITE OUTFILE = "list_01.sps" /separate.
WRITE OUTFILE = "list_01.sps" /space.
如果只有一个变量具有相同的列表(例如:V1),则可以正常工作.但是,如果有多个变量具有相同的列表,它会复制代码的次数与变量的数量一样多(例如:V2、V4 和 V5).
If there is only one variable with same list (ex: V1), it works ok. However, if there is more than one variable having the same list, it reproduces the codes as much times as number of variables (Ex: V2, V4 and V5).
运行上面的代码后,我有什么(例如:V2、V4 和 V5):
What I have (Ex: V2, V4 and V5), after running code above:
可变标签
V2工作"
.
价值标签
V2
1 "是的"
2 "没有"
****************************************************.
可变标签
V4已婚"
.
价值标签
V4
1 "是的"
2 "没有"
****************************************************.
可变标签
V5儿童"
.
价值标签
V5
1 "是的"
2 "没有"
****************************************************.
VARIABLE LABELS
V2 "Work"
.
VALUE LABELS
V2
1 " Yes "
2 " No "
************************************************.
VARIABLE LABELS
V4 "Married"
.
VALUE LABELS
V4
1 " Yes "
2 " No "
************************************************.
VARIABLE LABELS
V5 "Kids"
.
VALUE LABELS
V5
1 " Yes "
2 " No "
************************************************.
我想要的:
可变标签
V2工作"
V4已婚"
V5儿童"
.
价值标签
V2 V4 V5
1 "是的"
2 "没有"
VARIABLE LABELS
V2 "Work"
V4 "Married"
V5 "Kids"
.
VALUE LABELS
V2 V4 V5
1 " Yes "
2 " No "
推荐答案
我认为可能有一些方法可以更好地自动化整个过程,包括使用第二个数据源.但是对于这个问题的范围,我会建议一种方法来获得您具体要求的内容.
I think there are probably ways to automate the whole process better, including the use of your second data source. But for the scope of this question I will suggest a way to get what you asked for specifically.
关键是为第一行和最后一行构建具有特殊条件的命令:
The key is to build the command with special conditions for first and last lines:
string cmd1 cmd2 (a200).
sort cases by code.
match files /file=* /first=first /last=last /by code. /* marking first and last lines.
do if first.
compute cmd1="VARIABLE LABELS".
compute cmd2="VALUE LABELS".
end if.
if not first cmd1=concat(rtrim(cmd1), " /"). /* "/" only appears from the second varname.
compute cmd1=concat(rtrim(cmd1), " ", Var_label).
compute cmd2=concat(rtrim(cmd2), " ", Var).
do if last.
compute cmd1=concat(rtrim(cmd1), " .").
compute cmd2=concat(rtrim(cmd2), " ", ' 1 " Yes " 2 "No". ').
end if.
exe.
命令现在已经准备好了,但我们不想把它们弄混,所以我们将它们一个一个地堆叠起来,然后才将它们写出来:
The commands are now ready, but we don't want to get them mixed up so we'll stack them one under the other, and only then write them out:
add files /file=* /rename cmd1=cmd /file=* /rename cmd2=cmd.
exe.
WRITE OUTFILE = "var definitions.sps" / cmd .
exe.
请注意,上面的代码假设您已经运行了 select cases if code = ...
并且在所有剩余的行中只有一个 code
.
另请注意,我在末尾添加了一个 exe.
命令 - 不运行新语法将显示为空.
Note that the code above assumes you've already run a select cases if code = ...
and that there is a single code
in all the remaining lines.
Note also I added an exe.
command at the end - without running that the new syntax will appear empty.
这篇关于在 SPSS 中生成语法的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!