How can I tell SPSS, that it should only run a syntaxcommand if a condition with a macrovariable is true

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

_Melli_
Posts: 1
Joined: Wed Nov 02, 2016 9:20 am

How can I tell SPSS, that it should only run a syntaxcommand if a condition with a macrovariable is true

Postby _Melli_ » Wed Nov 02, 2016 9:25 am

Hello,

I want to create a routine that reads and labels a CSV-file depending on two cases:
There's two versions of the CSV-file. The only differences are the filename (version1: data_g.csv and version2: data_s.csv) and one variable (version1: EF1 and version2: EF2).

The user would define the version in use at the beginning (like 'DEFINE !version () 'g' !ENDDEFINE.') by changing 'g' to 's' or leaving it.

After that, a routine would run that reads the CSV-file and assignes variale labels and value labels:

GET DATA
/TYPE=TXT
/FILE=!path+"data_"+!version+".csv"
/DELCASE=LINE
/DELIMITERS=";"
/ARRANGEMENT=DELIMITED
/FIRSTCASE=2
/IMPORTCASE=ALL
/VARIABLES=
EF1 F2.0
EF2 F2.0
EF3 F5.0
...
CACHE.
EXECUTE.

VARIABLE LABELS EF1 "BLABLA1".
VARIABLE LABELS EF2 "BLABLA2".
VARIABLE LABELS EF3 "BLABLA3".

VALUE LABELS EF1
1 "BLABLA1".
VALUE LABELS EF2
1 "BLABLA2".
VALUE LABELS EF3
1 "BLABLA3".

SAVE OUTFILE=!path+!data_OUT.
EXECUTE.

Now how do I set a condition that makes SPSS read the right file (assign the right labels,... etc) based on the used version s or g?
Without a condition, I get an error because one variable can't be found.

I've already solved this problem in SAS and stata using macro variables:

stata:
if ${version} >= g {
label variable EF1 "Blabla1"
}

or in SAS inside a macro:
%if &version = g %then %do;
label EF1 = "Blabla1";
%end;

Unfortunately, macros in SPSS don't come to me that naturally. I've been poring over this for quite some time and think there has to be an easy solution. I'd be very happy if anyone had an idea how to solve the problem.
I use IBM SPSS Statistics 20.

TIA,
Melli

Who is online

Users browsing this forum: No registered users and 1 guest

cron