Global macro variable??

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

lucyg39
Posts: 2
Joined: Thu Jul 17, 2014 8:52 am

Global macro variable??

Postby lucyg39 » Thu Jul 17, 2014 9:32 am

I'm a SAS user and quite new to SPSS. I have 6 pieces of SPSS syntax that need to be run with a date change every so often.
I've set up a macro for the date in each piece of code but would like to run them all through a single piece of syntax using the include command. Is there a way to set the macro variable in the new syntax file such that it will update each of the six pieces of code without me needing to open and edit them each time?

So I have a.sps, b.sps, c.sps, d.sps, e.sps & f.sps with a macro variable in each called !date1.
I've then created a new syntax MASTER.sps:
include file "a.sps".
include file "b.sps".
include file "c.sps".
include file "d.sps".
include file "e.sps".
include file "f.sps".

Can I create a global date1 macro variable in the MASTER.sps file so that I can change the date in the master and it will carry through a,b,c,d,e & f??
RubenGeert
Posts: 100
Joined: Mon May 19, 2014 6:06 am

Re: Global macro variable??

Postby RubenGeert » Thu Jul 17, 2014 2:25 pm

Yes, that should work just fine.

P.s. be aware that in SPSS macros are somewhat deprecated in favor of Python, which is way more powerful and flexible. Also, see http://www.spss-tutorials.com/introduci ... t-and-why/

Best,

Ruben
lucyg39
Posts: 2
Joined: Thu Jul 17, 2014 8:52 am

Re: Global macro variable??

Postby lucyg39 » Thu Jul 17, 2014 3:22 pm

Thanks Ruben.

I'll have a look at the Python stuff but I've never used it before.

As for the global macro, how do I set it? I've tried just putting the !let !date1 = in the master file before the include commands but this doesn't work :(

Lucy
RubenGeert
Posts: 100
Joined: Mon May 19, 2014 6:06 am

Re: Global macro variable??

Postby RubenGeert » Fri Jul 18, 2014 6:54 am

In MASTER.sps, use something like

!define !mydate() 2014 !enddefine.

In an INSERTed syntax file use

compute somedate = !mydate.

I did assume that the latter command is not in a MACRO. If that assumption doesn't hold, I believe you can use !EVAL(!mydate) instead but I'm not 100% sure on that since I long since abandoned macros. Could you try that first?

Who is online

Users browsing this forum: No registered users and 2 guests

cron