Macro for unfixed variables

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Macro for unfixed variables

TIFFANY SWINIMER-2
Hey there,

I'm working with 28 files that have 51 fixed variables and 7 unfixed (nested maybe?) variables.
The fixed variables are fine, I have a macro reading them in, then merging them together then saving as one big file. No problems. However, the 7 nested variables are causing me some pain. They depend on another variable in the file called number_of_names. (ie if number_of_names = 6, those 7 variables need to be read in 6 times. number_of_names can be any number from 1 to 500). What I would like add to the macro would go something like this;

if (number_of_names = 1) then
*input 7 nested variables.

do n = 2 to 500
if (number_of_names >= n) then
*repeat the first 51 variables and add 7 nested variables
else (!break)

I'm not quite sure if this can be done or not.... but I'm really hoping someone can help.

Thanks

Tiffany

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Macro for unfixed variables

Richard Ristow
At 10:47 AM 2/20/2008, TIFFANY SWINIMER wrote:

>I'm working with 28 files that have 51 fixed variables and 7 unfixed
>(nested maybe?) variables. The fixed variables are fine, I have a
>macro reading them in, then merging them together then saving as one
>big file. No problems. However, the 7 nested variables are causing
>me some pain. They depend on another variable in the file called
>number_of_names. (ie if number_of_names = 6, those 7 variables need
>to be read in 6 times. number_of_names can be any number from 1 to 500).
>
>What I would like add to the macro would go something like this;
>
>if (number_of_names = 1) then
>*input 7 nested variables.
>
>do n = 2 to 500
>if (number_of_names >= n) then
>*repeat the first 51 variables and add 7 nested variables
>else (!break)

How you do it, depends on how your input files are structured: For
each instance, one record with the 51 variables, then as many as
necessary with a copy each of the 7 variables? Or (more likely, I
suppose), one record with the 51 variables, then in the same record
as many instances as necessary of the 7 variables?

You don't want macro looping. If you have the second case (one record
per instance), look at the REPEATING DATA command within an INPUT
PROGRAM. If that doesn't serve your turn, post again, saying more
about how you are receiving your input.

OK, further: If your input is already in SPSS form, you probably want
either VARSTOCASES (if there's one file with both the 'fixed' and the
'nested' variables), or MATCH FILES with the /TABLE subcommand (if
the fixed and nested variables are in separate files).

I hope this is a useful start, at least in defining the questions.

-Good luck,
  Richard

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD