separate output-files for different groups

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

separate output-files for different groups

Lars Balzer
Dear all,

I have the following problem:

My data contains several thousand observations within about more than
100 groups.
With
SORT CASES BY group.
SPLIT FILE SEPARATE BY group.
I am running some frequencies and other stuff for each group, which
produces one large output-file.
I would love to have separate output files, one for each group.
Then it would be perfect when the output-files could be named as the
group (from the variable group).

Is this possible with syntax or something else? I am using version 18.0
I really do not want to produce >100 outputs manually... ;-)

Thanks for any help,
  Lars

=====================
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: separate output-files for different groups

Ruben Geert van den Berg
Dear Lars,
 
Producing 100+ output files can be automated easily with a basic macro. However, I've no clue (yet) how to get the group names into the file names. The syntax below will produce output_no_1 for group 1, a.s.o..
 
Best regards!

Ruben van den Berg

Methodologist

TNS NIPO

E: [hidden email]

P: +31 20 522 5738

I: www.tns-nipo.com

 
cd'C:\Documents and Settings\BERGR\Desktop\big_test'.
 
*Create data.
 
inp pro.
loop id=1 to 10000.
end cas.
end loop.
end fil.
end inp pro.
comp group=rnd(rv.uni(.5,100.5)).
comp interestingvariable=rnd(rv.uni(.5,5.5)).
 
*Macro definition.
 
define !outputfiles()
!do !a=1 !to 100
comp filter=group=!a.
filter by filter.
output new.
fre interestingvariable.
output save outfile=!con("'output_no_",!a,"'").
output close all.
filt off.
!doend
!end.
 
*Macro call.
 
!outputfiles.



 

> Date: Fri, 5 Feb 2010 11:02:38 +0100
> From: [hidden email]
> Subject: separate output-files for different groups
> To: [hidden email]
>
> Dear all,
>
> I have the following problem:
>
> My data contains several thousand observations within about more than
> 100 groups.
> With
> SORT CASES BY group.
> SPLIT FILE SEPARATE BY group.
> I am running some frequencies and other stuff for each group, which
> produces one large output-file.
> I would love to have separate output files, one for each group.
> Then it would be perfect when the output-files could be named as the
> group (from the variable group).
>
> Is this possible with syntax or something else? I am using version 18.0
> I really do not want to produce >100 outputs manually... ;-)
>
> Thanks for any help,
> Lars
>
> =====================
> 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


Express yourself instantly with MSN Messenger! MSN Messenger
Reply | Threaded
Open this post in threaded view
|

Re: separate output-files for different groups

Lars Balzer
Thanks a lot Ruben, I am a step further now.

Regarding file names:
I am experimenting with my group variable as a string and
using
!do !a=1 !to 100
with strings, but that does not work.
Also
!do !a !in (...)
is not successful with strings.

Is there a way to use !do... with strings (something like 'use all
strings that occur in the group-variable, maybe in alphabetical order')?

Best,
  Lars



Ruben van den Berg schrieb:

> Dear Lars,
>
> Producing 100+ output files can be automated easily with a basic macro.
> However, I've no clue (yet) how to get the group names into the file
> names. The syntax below will produce output_no_1 for group 1, a.s.o..
>
> Best regards!
>
> *Ruben van den Berg*
>
> *Methodologist*
>
> TNS NIPO
>
> E: [hidden email] <mailto:[hidden email]>
>
> P: +31 20 522 5738
>
> I: www.tns-nipo.com <http://www.tns-nipo.com>
>
>
> cd'C:\Documents and Settings\BERGR\Desktop\big_test'.
>
> *Create data.
>
> inp pro.
> loop id=1 to 10000.
> end cas.
> end loop.
> end fil.
> end inp pro.
> comp group=rnd(rv.uni(.5,100.5)).
> comp interestingvariable=rnd(rv.uni(.5,5.5)).
>
> *Macro definition.
>
> define !outputfiles()
> !do !a=1 !to 100
> comp filter=group=!a.
> filter by filter.
> output new.
> fre interestingvariable.
> output save outfile=!con("'output_no_",!a,"'").
> output close all.
> filt off.
> !doend
> !end.
>
> *Macro call.
>
> !outputfiles.
>
>
>
>
>
>  > Date: Fri, 5 Feb 2010 11:02:38 +0100
>  > From: [hidden email]
>  > Subject: separate output-files for different groups
>  > To: [hidden email]
>  >
>  > Dear all,
>  >
>  > I have the following problem:
>  >
>  > My data contains several thousand observations within about more than
>  > 100 groups.
>  > With
>  > SORT CASES BY group.
>  > SPLIT FILE SEPARATE BY group.
>  > I am running some frequencies and other stuff for each group, which
>  > produces one large output-file.
>  > I would love to have separate output files, one for each group.
>  > Then it would be perfect when the output-files could be named as the
>  > group (from the variable group).
>  >
>  > Is this possible with syntax or something else? I am using version 18.0
>  > I really do not want to produce >100 outputs manually... ;-)
>  >
>  > Thanks for any help,
>  > Lars
>  >
>  > =====================
>  > 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
>
> ------------------------------------------------------------------------
> Express yourself instantly with MSN Messenger! MSN Messenger
> <http://clk.atdmt.com/AVE/go/onm00200471ave/direct/01/>

=====================
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: separate output-files for different groups

Jon K Peck

Here's how I would solve problems like this.  This is a general problem - running arbitrary blocks of syntax over a partition of a dataset - that I have been mulling over for a while.  I started on a solution a while back but ran into some technical obstacles.  Now I see how to do it.  I created the function spssaux2.generalizedSplit a while ago, but it requires as many data passes as there are distinct split values.

First I would generate a sav file for each split value.
Then I would use the programmability function spssaux3.ApplySyntaxToFiles,  That function takes a syntax file and iterates over the selected files in a directory, producing a separate output file and, optionally, a new data file, for each with an optional log.  (I demonstrated that function last year at the European Directions conference).

There are two obstacles here.  First, if you are not a programmability person, ApplySyntaxToFiles might be a little foreign.  It's a pretty simple function, but I am going to turn it into an extension command with dialog box so that it can be used with no programmability skills at all.

The bigger obstacle is how to generate all those SAV files.  The mechanism built into SPSS for this sort of thing is XSAVE.  That is very efficient, but it has two problems.  First, there is a limit on how many XSAVES you can have.  We raised that limit a release or two ago,  Currently the limit is 64, but it used to be much smaller.

Second is how you supply the names (and conditions) for this without having to know all the split values in advance.  The solution for both problems is to generate the XSAVE syntax using programmability - that's another extension command.

I expect that I will have a solution within a week, depending on what else comes up.  As usual, it will be posted to Developer Central.

Jon Peck
SPSS, an IBM Company
[hidden email]
312-651-3435



From: Lars Balzer <[hidden email]>
To: [hidden email]
Date: 02/07/2010 03:22 PM
Subject: Re: [SPSSX-L] separate output-files for different groups
Sent by: "SPSSX(r) Discussion" <[hidden email]>





Thanks a lot Ruben, I am a step further now.

Regarding file names:
I am experimenting with my group variable as a string and
using
!do !a=1 !to 100
with strings, but that does not work.
Also
!do !a !in (...)
is not successful with strings.

Is there a way to use !do... with strings (something like 'use all
strings that occur in the group-variable, maybe in alphabetical order')?

Best,
 Lars



Ruben van den Berg schrieb:
> Dear Lars,
>
> Producing 100+ output files can be automated easily with a basic macro.
> However, I've no clue (yet) how to get the group names into the file
> names. The syntax below will produce output_no_1 for group 1, a.s.o..
>
> Best regards!
>
> *Ruben van den Berg*
>
> *Methodologist*
>
> TNS NIPO
>
> E: [hidden email] <
mailto:ruben_van_den_berg@...>
>
> P: +31 20 522 5738
>
> I:
www.tns-nipo.com <http://www.tns-nipo.com>
>
>
> cd'C:\Documents and Settings\BERGR\Desktop\big_test'.
>
> *Create data.
>
> inp pro.
> loop id=1 to 10000.
> end cas.
> end loop.
> end fil.
> end inp pro.
> comp group=rnd(rv.uni(.5,100.5)).
> comp interestingvariable=rnd(rv.uni(.5,5.5)).
>
> *Macro definition.
>
> define !outputfiles()
> !do !a=1 !to 100
> comp filter=group=!a.
> filter by filter.
> output new.
> fre interestingvariable.
> output save outfile=!con("'output_no_",!a,"'").
> output close all.
> filt off.
> !doend
> !end.
>
> *Macro call.
>
> !outputfiles.
>
>
>
>
>
>  > Date: Fri, 5 Feb 2010 11:02:38 +0100
>  > From: [hidden email]
>  > Subject: separate output-files for different groups
>  > To: [hidden email]
>  >
>  > Dear all,
>  >
>  > I have the following problem:
>  >
>  > My data contains several thousand observations within about more than
>  > 100 groups.
>  > With
>  > SORT CASES BY group.
>  > SPLIT FILE SEPARATE BY group.
>  > I am running some frequencies and other stuff for each group, which
>  > produces one large output-file.
>  > I would love to have separate output files, one for each group.
>  > Then it would be perfect when the output-files could be named as the
>  > group (from the variable group).
>  >
>  > Is this possible with syntax or something else? I am using version 18.0
>  > I really do not want to produce >100 outputs manually... ;-)
>  >
>  > Thanks for any help,
>  > Lars
>  >
>  > =====================
>  > 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
>
> ------------------------------------------------------------------------
> Express yourself instantly with MSN Messenger! MSN Messenger
> <
http://clk.atdmt.com/AVE/go/onm00200471ave/direct/01/>

=====================
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: separate output-files for different groups

Ruben Geert van den Berg
In reply to this post by Lars Balzer
Dear Lars,
 
I've been wondering for days whether your value labels could be inserted into the filenames with just syntax (since I haven't learned Python yet). I can hardly believe there's no possibility at all but -so far- I've no clue how/whether it could be accomplished. Well, OK, I do have a clue but I think it will turn out to be beyond my capabilities: providing a list of value labels (generated with OMS - display dictionary/variables=group) as an extra macro argument and -well, turning the group into a string could provide the possibility of using some sort of "temp. sel if group="bla". structure... OK, probably way too complicated...
 
Didn't you try the python solution by Albert-Jan? Perhaps this is the fastest way to just solve the problem at hand.
 
Best regards,

Ruben van den Berg

Methodologist

TNS NIPO

E: [hidden email]

P: +31 20 522 5738

I: www.tns-nipo.com




 

> Date: Sun, 7 Feb 2010 23:20:27 +0100
> From: [hidden email]
> Subject: Re: separate output-files for different groups
> To: [hidden email]
>
> Thanks a lot Ruben, I am a step further now.
>
> Regarding file names:
> I am experimenting with my group variable as a string and
> using
> !do !a=1 !to 100
> with strings, but that does not work.
> Also
> !do !a !in (...)
> is not successful with strings.
>
> Is there a way to use !do... with strings (something like 'use all
> strings that occur in the group-variable, maybe in alphabetical order')?
>
> Best,
> Lars
>
>
>
> Ruben van den Berg schrieb:
> > Dear Lars,
> >
> > Producing 100+ output files can be automated easily with a basic macro.
> > However, I've no clue (yet) how to get the group names into the file
> > names. The syntax below will produce output_no_1 for group 1, a.s.o..
> >
> > Best regards!
> >
> > *Ruben van den Berg*
> >
> > *Methodologist*
> >
> > TNS NIPO
> >
> > E: [hidden email] <mailto:[hidden email]>
> >
> > P: +31 20 522 5738
> >
> > I: www.tns-nipo.com <http://www.tns-nipo.com>
> >
> >
> > cd'C:\Documents and Settings\BERGR\Desktop\big_test'.
> >
> > *Create data.
> >
> > inp pro.
> > loop id=1 to 10000.
> > end cas.
> > end loop.
> > end fil.
> > end inp pro.
> > comp group=rnd(rv.uni(.5,100.5)).
> > comp interestingvariable=rnd(rv.uni(.5,5.5)).
> >
> > *Macro definition.
> >
> > define !outputfiles()
> > !do !a=1 !to 100
> > comp filter=group=!a.
> > filter by filter.
> > output new.
> > fre interestingvariable.
> > output save outfile=!con("'output_no_",!a,"'").
> > output close all.
> > filt off.
> > !doend
> > !end.
> >
> > *Macro call.
> >
> > !outputfiles.
> >
> >
> >
> >
> >
> > > Date: Fri, 5 Feb 2010 11:02:38 +0100
> > > From: [hidden email]
> > > Subject: separate output-files for different groups
> > > To: [hidden email]
> > >
> > > Dear all,
> > >
> > > I have the following problem:
> > >
> > > My data contains several thousand observations within about more than
> > > 100 groups.
> > > With
> > > SORT CASES BY group.
> > > SPLIT FILE SEPARATE BY group.
> > > I am running some frequencies and other stuff for each group, which
> > > produces one large output-file.
> > > I would love to have separate output files, one for each group.
> > > Then it would be perfect when the output-files could be named as the
> > > group (from the variable group).
> > >
> > > Is this possible with syntax or something else? I am using version 18.0
> > > I really do not want to produce >100 outputs manually... ;-)
> > >
> > > Thanks for any help,
> > > Lars
> > >
> > > =====================
> > > 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
> >
> > ------------------------------------------------------------------------
> > Express yourself instantly with MSN Messenger! MSN Messenger
> > <http://clk.atdmt.com/AVE/go/onm00200471ave/direct/01/>
>
> =====================
> 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


Express yourself instantly with MSN Messenger! MSN Messenger
Reply | Threaded
Open this post in threaded view
|

Re: separate output-files for different groups

Ruben Geert van den Berg
In reply to this post by Lars Balzer
Dear Lars,
 
Say 'hi' to probably the ugliest syntax written in 2010 so far. For these fake data, it seems to do just what it should. If you would like to use it, some settings should be changed, most notably "string st_group(a3)." will be probably too short for your actual labels.
 
Good luck, if I can provide any further assistance let me know!

Ruben van den Berg

Methodologist

TNS NIPO

E: [hidden email]

P: +31 20 522 5738

I: www.tns-nipo.com

 
*basic settings.

cd 'c:\temp'.
set seed 1.
datas clo all.
 
*create fake data.
 
inp pro.
loop id=1 to 100.
end cas.
end loop.
end fil.
end inp pro.
comp group=rnd(rv.uni(.5,4.5)).
comp interestingvariable=rnd(rv.uni(.5,3.5)).
val lab group 1'bla'2'blo'3'bli'4'blu'.
string st_group(a3).
comp st_group=valuelabel(group).
datas nam d1.

*Macro definition.
 
define !outputfiles(!pos !cha('/'))
!do !a !in (!1)
output new.
tit !con('"This is the output of subgroup ',!a,'"').
temp.
sel if st_group eq !con('"',!a,'"').
fre interestingvariable.
output save outfile=!con("'output_no_",!a,".spv'").
output close all.
!doend
!end.
 
*Create syntax containing a possibly very long macro call.
 
DATASET DECLARE  fre.
OMS
  /SELECT TABLES
  /IF COMMANDS=['Frequencies'] SUBTYPES=['Frequencies']
  /DESTINATION FORMAT=SAV NUMBERED=TableNumber_
   OUTFILE='fre' VIEWER=NO
  /TAG='fre'.
fre st_group.
omsend tag=['fre'].
datas act fre.
sel if var2 ne "Total".
comp id=$casenum.
comp dum=0.
agg
/out * mod add
/bre dum
/no_cats=max(id).
exe.
 
*Now I'm going to create the actual syntax file.
 
do if id=1.
wri out '$syn.sps'/'!outputfiles '.
end if.
wri out '$syn.sps'/var2.
do if id=no_cats.
wri out '$syn.sps'/'/.'.
end if.
exe.
 
*Now we return to the original data.
 
datas clo fre.
datas act d1.
 
*Now we run the macro call.
 
ins fil='$syn.sps'.
 
*And delete the syntax.

era fil='$syn.sps'.
 
*End.


 

> Date: Sun, 7 Feb 2010 23:20:27 +0100
> From: [hidden email]
> Subject: Re: separate output-files for different groups
> To: [hidden email]
>
> Thanks a lot Ruben, I am a step further now.
>
> Regarding file names:
> I am experimenting with my group variable as a string and
> using
> !do !a=1 !to 100
> with strings, but that does not work.
> Also
> !do !a !in (...)
> is not successful with strings.
>
> Is there a way to use !do... with strings (something like 'use all
> strings that occur in the group-variable, maybe in alphabetical order')?
>
> Best,
> Lars
>
>
>
> Ruben van den Berg schrieb:
> > Dear Lars,
> >
> > Producing 100+ output files can be automated easily with a basic macro.
> > However, I've no clue (yet) how to get the group names into the file
> > names. The syntax below will produce output_no_1 for group 1, a.s.o..
> >
> > Best regards!
> >
> > *Ruben van den Berg*
> >
> > *Methodologist*
> >
> > TNS NIPO
> >
> > E: [hidden email] <mailto:[hidden email]>
> >
> > P: +31 20 522 5738
> >
> > I: www.tns-nipo.com <http://www.tns-nipo.com>
> >
> >
> > cd'C:\Documents and Settings\BERGR\Desktop\big_test'.
> >
> > *Create data.
> >
> > inp pro.
> > loop id=1 to 10000.
> > end cas.
> > end loop.
> > end fil.
> > end inp pro.
> > comp group=rnd(rv.uni(.5,100.5)).
> > comp interestingvariable=rnd(rv.uni(.5,5.5)).
> >
> > *Macro definition.
> >
> > define !outputfiles()
> > !do !a=1 !to 100
> > comp filter=group=!a.
> > filter by filter.
> > output new.
> > fre interestingvariable.
> > output save outfile=!con("'output_no_",!a,"'").
> > output close all.
> > filt off.
> > !doend
> > !end.
> >
> > *Macro call.
> >
> > !outputfiles.
> >
> >
> >
> >
> >
> > > Date: Fri, 5 Feb 2010 11:02:38 +0100
> > > From: [hidden email]
> > > Subject: separate output-files for different groups
> > > To: [hidden email]
> > >
> > > Dear all,
> > >
> > > I have the following problem:
> > >
> > > My data contains several thousand observations within about more than
> > > 100 groups.
> > > With
> > > SORT CASES BY group.
> > > SPLIT FILE SEPARATE BY group.
> > > I am running some frequencies and other stuff for each group, which
> > > produces one large output-file.
> > > I would love to have separate output files, one for each group.
> > > Then it would be perfect when the output-files could be named as the
> > > group (from the variable group).
> > >
> > > Is this possible with syntax or something else? I am using version 18.0
> > > I really do not want to produce >100 outputs manually... ;-)
> > >
> > > Thanks for any help,
> > > Lars
> > >
> > > =====================
> > > 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
> >
> > ------------------------------------------------------------------------
> > Express yourself instantly with MSN Messenger! MSN Messenger
> > <http://clk.atdmt.com/AVE/go/onm00200471ave/direct/01/>
>
> =====================
> 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


New Windows 7: Simplify what you do everyday. Find the right PC for you.
Reply | Threaded
Open this post in threaded view
|

Re: separate output-files for different groups

Lars Balzer
In reply to this post by Jon K Peck
Jon,

thank you very much for your help and ideas.
I am looking forward to testing your solution.

Best regards,
  Lars


Jon K Peck schrieb:

>
> Here's how I would solve problems like this.  This is a general problem
> - running arbitrary blocks of syntax over a partition of a dataset -
> that I have been mulling over for a while.  I started on a solution a
> while back but ran into some technical obstacles.  Now I see how to do
> it.  I created the function spssaux2.generalizedSplit a while ago, but
> it requires as many data passes as there are distinct split values.
>
> First I would generate a sav file for each split value.
> Then I would use the programmability function
> spssaux3.ApplySyntaxToFiles,  That function takes a syntax file and
> iterates over the selected files in a directory, producing a separate
> output file and, optionally, a new data file, for each with an optional
> log.  (I demonstrated that function last year at the European Directions
> conference).
>
> There are two obstacles here.  First, if you are not a programmability
> person, ApplySyntaxToFiles might be a little foreign.  It's a pretty
> simple function, but I am going to turn it into an extension command
> with dialog box so that it can be used with no programmability skills at
> all.
>
> The bigger obstacle is how to generate all those SAV files.  The
> mechanism built into SPSS for this sort of thing is XSAVE.  That is very
> efficient, but it has two problems.  First, there is a limit on how many
> XSAVES you can have.  We raised that limit a release or two ago,
>  Currently the limit is 64, but it used to be much smaller.
>
> Second is how you supply the names (and conditions) for this without
> having to know all the split values in advance.  The solution for both
> problems is to generate the XSAVE syntax using programmability - that's
> another extension command.
>
> I expect that I will have a solution within a week, depending on what
> else comes up.  As usual, it will be posted to Developer Central.
>
> Jon Peck
> SPSS, an IBM Company
> [hidden email]
> 312-651-3435
>
>
> From:         Lars Balzer <[hidden email]>
> To:   [hidden email]
> Date:         02/07/2010 03:22 PM
> Subject:      Re: [SPSSX-L] separate output-files for different groups
> Sent by:      "SPSSX(r) Discussion" <[hidden email]>
>
>
> ------------------------------------------------------------------------
>
>
>
> Thanks a lot Ruben, I am a step further now.
>
> Regarding file names:
> I am experimenting with my group variable as a string and
> using
> !do !a=1 !to 100
> with strings, but that does not work.
> Also
> !do !a !in (...)
> is not successful with strings.
>
> Is there a way to use !do... with strings (something like 'use all
> strings that occur in the group-variable, maybe in alphabetical order')?
>
> Best,
>  Lars
>
>
>
> Ruben van den Berg schrieb:
>  > Dear Lars,
>  >
>  > Producing 100+ output files can be automated easily with a basic macro.
>  > However, I've no clue (yet) how to get the group names into the file
>  > names. The syntax below will produce output_no_1 for group 1, a.s.o..
>  >
>  > Best regards!
>  >
>  > *Ruben van den Berg*
>  >
>  > *Methodologist*
>  >
>  > TNS NIPO
>  >
>  > E: [hidden email] <mailto:[hidden email]>
>  >
>  > P: +31 20 522 5738
>  >
>  > I: www.tns-nipo.com <http://www.tns-nipo.com <http://www.tns-nipo.com/>>
>  >
>  >
>  > cd'C:\Documents and Settings\BERGR\Desktop\big_test'.
>  >
>  > *Create data.
>  >
>  > inp pro.
>  > loop id=1 to 10000.
>  > end cas.
>  > end loop.
>  > end fil.
>  > end inp pro.
>  > comp group=rnd(rv.uni(.5,100.5)).
>  > comp interestingvariable=rnd(rv.uni(.5,5.5)).
>  >
>  > *Macro definition.
>  >
>  > define !outputfiles()
>  > !do !a=1 !to 100
>  > comp filter=group=!a.
>  > filter by filter.
>  > output new.
>  > fre interestingvariable.
>  > output save outfile=!con("'output_no_",!a,"'").
>  > output close all.
>  > filt off.
>  > !doend
>  > !end.
>  >
>  > *Macro call.
>  >
>  > !outputfiles.
>  >
>  >
>  >
>  >
>  >
>  >  > Date: Fri, 5 Feb 2010 11:02:38 +0100
>  >  > From: [hidden email]
>  >  > Subject: separate output-files for different groups
>  >  > To: [hidden email]
>  >  >
>  >  > Dear all,
>  >  >
>  >  > I have the following problem:
>  >  >
>  >  > My data contains several thousand observations within about more than
>  >  > 100 groups.
>  >  > With
>  >  > SORT CASES BY group.
>  >  > SPLIT FILE SEPARATE BY group.
>  >  > I am running some frequencies and other stuff for each group, which
>  >  > produces one large output-file.
>  >  > I would love to have separate output files, one for each group.
>  >  > Then it would be perfect when the output-files could be named as the
>  >  > group (from the variable group).
>  >  >
>  >  > Is this possible with syntax or something else? I am using version
> 18.0
>  >  > I really do not want to produce >100 outputs manually... ;-)
>  >  >
>  >  > Thanks for any help,
>  >  > Lars
>  >  >
>  >  > =====================
>  >  > 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
>  >
>  > ------------------------------------------------------------------------
>  > Express yourself instantly with MSN Messenger! MSN Messenger
>  > <http://clk.atdmt.com/AVE/go/onm00200471ave/direct/01/>
>
> =====================
> 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
>

=====================
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: separate output-files for different groups

Lars Balzer
In reply to this post by Ruben Geert van den Berg
Ruben,

I very much appreciate to say this "hi" ;-)

It is midnight here, so I will have a break now. Tomorrow I will check
this out!

Thank you very much!
I will keep you informed about my progress (offlist, if there is nothing
to learn for others).

Best,
  Lars


Ruben van den Berg schrieb:

> Dear Lars,
>
> Say 'hi' to probably the ugliest syntax written in 2010 so far. For
> these fake data, it seems to do just what it should. If you would like
> to use it, some settings should be changed, most notably "string
> st_group(a3)." will be probably too short for your actual labels.
>
> Good luck, if I can provide any further assistance let me know!
>
> *Ruben van den Berg*
>
> *Methodologist*
>
> TNS NIPO
>
> E: [hidden email] <mailto:[hidden email]>
>
> P: +31 20 522 5738
>
> I: www.tns-nipo.com <http://www.tns-nipo.com>
>
>
> *basic settings.
>
> cd 'c:\temp'.
> set seed 1.
> datas clo all.
>
> *create fake data.
>
> inp pro.
> loop id=1 to 100.
> end cas.
> end loop.
> end fil.
> end inp pro.
> comp group=rnd(rv.uni(.5,4.5)).
> comp interestingvariable=rnd(rv.uni(.5,3.5)).
> val lab group 1'bla'2'blo'3'bli'4'blu'.
> string st_group(a3).
> comp st_group=valuelabel(group).
> datas nam d1.
>
> *Macro definition.
>
> define !outputfiles(!pos !cha('/'))
> !do !a !in (!1)
> output new.
> tit !con('"This is the output of subgroup ',!a,'"').
> temp.
> sel if st_group eq !con('"',!a,'"').
> fre interestingvariable.
> output save outfile=!con("'output_no_",!a,".spv'").
> output close all.
> !doend
> !end.
>
> *Create syntax containing a possibly very long macro call.
>
> DATASET DECLARE  fre.
> OMS
>   /SELECT TABLES
>   /IF COMMANDS=['Frequencies'] SUBTYPES=['Frequencies']
>   /DESTINATION FORMAT=SAV NUMBERED=TableNumber_
>    OUTFILE='fre' VIEWER=NO
>   /TAG='fre'.
> fre st_group.
> omsend tag=['fre'].
> datas act fre.
> sel if var2 ne "Total".
> comp id=$casenum.
> comp dum=0.
> agg
> /out * mod add
> /bre dum
> /no_cats=max(id).
> exe.
>
> *Now I'm going to create the actual syntax file.
>
> do if id=1.
> wri out '$syn.sps'/'!outputfiles '.
> end if.
> wri out '$syn.sps'/var2.
> do if id=no_cats.
> wri out '$syn.sps'/'/.'.
> end if.
> exe.
>
> *Now we return to the original data.
>
> datas clo fre.
> datas act d1.
>
> *Now we run the macro call.
>
> ins fil='$syn.sps'.
>
> *And delete the syntax.
>
> era fil='$syn.sps'.
>
> *End.
>
>
>
>
>  > Date: Sun, 7 Feb 2010 23:20:27 +0100
>  > From: [hidden email]
>  > Subject: Re: separate output-files for different groups
>  > To: [hidden email]
>  >
>  > Thanks a lot Ruben, I am a step further now.
>  >
>  > Regarding file names:
>  > I am experimenting with my group variable as a string and
>  > using
>  > !do !a=1 !to 100
>  > with strings, but that does not work.
>  > Also
>  > !do !a !in (...)
>  > is not successful with strings.
>  >
>  > Is there a way to use !do... with strings (something like 'use all
>  > strings that occur in the group-variable, maybe in alphabetical order')?
>  >
>  > Best,
>  > Lars
>  >
>  >
>  >
>  > Ruben van den Berg schrieb:
>  > > Dear Lars,
>  > >
>  > > Producing 100+ output files can be automated easily with a basic macro.
>  > > However, I've no clue (yet) how to get the group names into the file
>  > > names. The syntax below will produce output_no_1 for group 1, a.s.o..
>  > >
>  > > Best regards!
>  > >
>  > > *Ruben van den Berg*
>  > >
>  > > *Methodologist*
>  > >
>  > > TNS NIPO
>  > >
>  > > E: [hidden email]
> <mailto:[hidden email]>
>  > >
>  > > P: +31 20 522 5738
>  > >
>  > > I: www.tns-nipo.com <http://www.tns-nipo.com>
>  > >
>  > >
>  > > cd'C:\Documents and Settings\BERGR\Desktop\big_test'.
>  > >
>  > > *Create data.
>  > >
>  > > inp pro.
>  > > loop id=1 to 10000.
>  > > end cas.
>  > > end loop.
>  > > end fil.
>  > > end inp pro.
>  > > comp group=rnd(rv.uni(.5,100.5)).
>  > > comp interestingvariable=rnd(rv.uni(.5,5.5)).
>  > >
>  > > *Macro definition.
>  > >
>  > > define !outputfiles()
>  > > !do !a=1 !to 100
>  > > comp filter=group=!a.
>  > > filter by filter.
>  > > output new.
>  > > fre interestingvariable.
>  > > output save outfile=!con("'output_no_",!a,"'").
>  > > output close all.
>  > > filt off.
>  > > !doend
>  > > !end.
>  > >
>  > > *Macro call.
>  > >
>  > > !outputfiles.
>  > >
>  > >
>  > >
>  > >
>  > >
>  > > > Date: Fri, 5 Feb 2010 11:02:38 +0100
>  > > > From: [hidden email]
>  > > > Subject: separate output-files for different groups
>  > > > To: [hidden email]
>  > > >
>  > > > Dear all,
>  > > >
>  > > > I have the following problem:
>  > > >
>  > > > My data contains several thousand observations within about more than
>  > > > 100 groups.
>  > > > With
>  > > > SORT CASES BY group.
>  > > > SPLIT FILE SEPARATE BY group.
>  > > > I am running some frequencies and other stuff for each group, which
>  > > > produces one large output-file.
>  > > > I would love to have separate output files, one for each group.
>  > > > Then it would be perfect when the output-files could be named as the
>  > > > group (from the variable group).
>  > > >
>  > > > Is this possible with syntax or something else? I am using
> version 18.0
>  > > > I really do not want to produce >100 outputs manually... ;-)
>  > > >
>  > > > Thanks for any help,
>  > > > Lars
>  > > >
>  > > > =====================
>  > > > 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
>  > >
>  > >
> ------------------------------------------------------------------------
>  > > Express yourself instantly with MSN Messenger! MSN Messenger
>  > > <http://clk.atdmt.com/AVE/go/onm00200471ave/direct/01/>
>  >
>  > =====================
>  > 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
>
> ------------------------------------------------------------------------
> New Windows 7: Simplify what you do everyday. Find the right PC for you.
> <http://windows.microsoft.com/shop>

=====================
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