1

I have a file with the following variables and associated formats.

ID --> String
Var1_flag1 --> Numeric
Var2_flag2 --> Numeric
Var3_flag1 --> Numeric
Var4_flag3 --> Numeric
Var5_flag3 --> Numeric
Var6_flag3 --> Numeric
Var7_flag2 --> Numeric
Var8_flag2 --> Numeric
Var9_flag1 --> Numeric

I would like to define the formats based on a regular expression within the variable names (rather than having to explicitly define the variables for each column name).

For example I would like all variables that have flag1 in the name to be formatted to F10.3, flag2 to be formatted to F10.2 and flag3 to be formatted to F10.1 and all columns that don't match these conditions to retain their existing format.

1 Answer 1

1

You can use spssinc select variables to create lists of variables according to an attribute like you described, and then use the list in your syntax. For example:

spssinc select variables macroname="!flag1" /properties pattern=".*flag1".
spssinc select variables macroname="!flag2" /properties pattern=".*flag2".
spssinc select variables macroname="!flag3" /properties pattern=".*flag3".
alter type !flag1 (F10.3) !flag2 (F10.2) !flag3 (F10.1) .
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.