|
I copied a macro from Raynald's SPSS site, but I'm having difficulties.
The purpose of the macro is to normalize a variable from 0 to 1, and it works fine...the first time I call it. Any other calls, however, complain that a file is already in use. Is there some way I can close or reset the file or dataset? The macro follows, along with part of the log. DEFINE !transf (var=!TOKENS(1) /newvar=!TOKENS(1)) COMPUTE dummy=1. AGGREGATE /OUTFILE='C:\temp\AGGR.SAV' /BREAK=dummy /minval = MIN (!var) /maxval = MAX(!var). MATCH FILES /FILE=* /TABLE='C:\Temp\AGGR.SAV' /BY dummy. COMPUTE !newvar=(!var-minval)/(maxval - minval). !ENDDEFINE. ---- SET MPRINT=yes. !transf var=RR1s newvar=RR1norm. 50 0 M> 51 0 M> . 52 0 M> COMPUTE dummy=1. 53 0 M> AGGREGATE /OUTFILE='C:\temp\AGGR.SAV' /BREAK=dummy /minval = MIN( RR1s ) /maxval = MAX( RR1s ). 54 0 M> MATCH FILES /FILE=* /TABLE='C:\Temp\AGGR.SAV' /BY dummy. 55 0 M> COMPUTE RR1norm =( RR1s -minval)/(maxval - minval) 56 0 M> . !transf var=RR5s newvar=RR5norm. 57 0 M> 58 0 M> . 59 0 M> COMPUTE dummy=1. 60 0 M> AGGREGATE /OUTFILE='C:\temp\AGGR.SAV' /BREAK=dummy /minval = MIN( RR5s ) /maxval = MAX( RR5s ). Error # 62 in column 20. Text: C:\temp\AGGR.SAV The file is already in use. Execution of this command stops. 61 0 M> MATCH FILES /FILE=* /TABLE='C:\Temp\AGGR.SAV' /BY dummy. 62 0 M> COMPUTE RR5norm =( RR5s -minval)/(maxval - minval) 63 0 M> . EXECUTE. 64 0 M> EXECUTE. SET MPRINT=no. 65 0 M> SET MPRINT=no. Mark Lavender Application Architect and Developer Finance IT ===================== 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 |
|
Hi Mark:
I had the same problem with a macro, and I solved it by inserting: CACHE. EXE. At the beginning of the macro definition: DEFINE !transf (var=!TOKENS(1) /newvar=!TOKENS(1)) CACHE. EXE. COMPUTE dummy=1. AGGREGATE /OUTFILE='C:\temp\AGGR.SAV' /BREAK=dummy /minval = MIN (!var) /maxval = MAX(!var). MATCH FILES /FILE=* /TABLE='C:\Temp\AGGR.SAV' /BY dummy. COMPUTE !newvar=(!var-minval)/(maxval - minval). !ENDDEFINE. It will slow a bit the execution of the macro if the file is very big, since it forces an "unnecessary" data pass (well, necessary since it makes the macro work OK). HTH, Marta GG El 04/10/2010 18:53, Mark Lavender escribió: > I copied a macro from Raynald's SPSS site, but I'm having difficulties. > > The purpose of the macro is to normalize a variable from 0 to 1, and it > works fine...the first time I call it. Any other calls, however, complain > that a file is already in use. Is there some way I can close or reset the > file or dataset? > > The macro follows, along with part of the log. > > DEFINE !transf (var=!TOKENS(1) /newvar=!TOKENS(1)) > COMPUTE dummy=1. > AGGREGATE /OUTFILE='C:\temp\AGGR.SAV' /BREAK=dummy /minval = MIN > (!var) /maxval = MAX(!var). > MATCH FILES /FILE=* /TABLE='C:\Temp\AGGR.SAV' /BY dummy. > > COMPUTE !newvar=(!var-minval)/(maxval - minval). > !ENDDEFINE. > > ---- > > SET MPRINT=yes. > !transf var=RR1s newvar=RR1norm. > 50 0 M> > 51 0 M> . > 52 0 M> COMPUTE dummy=1. > 53 0 M> AGGREGATE /OUTFILE='C:\temp\AGGR.SAV' /BREAK=dummy /minval = > MIN( RR1s ) /maxval = MAX( RR1s ). > 54 0 M> MATCH FILES /FILE=* /TABLE='C:\Temp\AGGR.SAV' /BY dummy. > 55 0 M> COMPUTE RR1norm =( RR1s -minval)/(maxval - minval) > 56 0 M> . > !transf var=RR5s newvar=RR5norm. > 57 0 M> > 58 0 M> . > 59 0 M> COMPUTE dummy=1. > 60 0 M> AGGREGATE /OUTFILE='C:\temp\AGGR.SAV' /BREAK=dummy /minval = > MIN( RR5s ) /maxval = MAX( RR5s ). > > Error # 62 in column 20. Text: C:\temp\AGGR.SAV > The file is already in use. > Execution of this command stops. > 61 0 M> MATCH FILES /FILE=* /TABLE='C:\Temp\AGGR.SAV' /BY dummy. > 62 0 M> COMPUTE RR5norm =( RR5s -minval)/(maxval - minval) > 63 0 M> . > EXECUTE. > 64 0 M> EXECUTE. > SET MPRINT=no. > 65 0 M> SET MPRINT=no. > > > Mark Lavender > Application Architect and Developer > Finance IT > > ===================== > 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 > -- For miscellaneous SPSS related statistical stuff, visit: http://gjyp.nl/marta/ ===================== 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 |
|
Administrator
|
In reply to this post by Mark Lavender-3
Mark,
Marta's post re CACHE. EXE. should work, BUT you REALLY don't need the temp file at all if you have a more recent version of SPSS. See AGGREGATE documentation (ie MODE=ADDVARIABLES). This eliminates the need for the MATCH as well. You need to be careful with later invocations and verify that the minval and maxval variables are populated correctly as they will already exist in the active file. In fact you will find that ONLY the first one will work as you have it here. If you go with the AGGREGATE.../MODE approach you will need to drop the minval and maxval in between invocations . Alternatively, amend your code by reversing the order of the TABLE and FILE subcommands. HTH, David On Mon, 4 Oct 2010 12:53:19 -0400, Mark Lavender <[hidden email]> wrote: >I copied a macro from Raynald's SPSS site, but I'm having difficulties. > >The purpose of the macro is to normalize a variable from 0 to 1, and it >works fine...the first time I call it. Any other calls, however, complain >that a file is already in use. Is there some way I can close or reset the >file or dataset? > >The macro follows, along with part of the log. > >DEFINE !transf (var=!TOKENS(1) /newvar=!TOKENS(1)) >COMPUTE dummy=1. >AGGREGATE /OUTFILE='C:\temp\AGGR.SAV' /BREAK=dummy /minval = MIN >(!var) /maxval = MAX(!var). >MATCH FILES /FILE=* /TABLE='C:\Temp\AGGR.SAV' /BY dummy. > >COMPUTE !newvar=(!var-minval)/(maxval - minval). >!ENDDEFINE. > >---- > >SET MPRINT=yes. >!transf var=RR1s newvar=RR1norm. > 50 0 M> > 51 0 M> . > 52 0 M> COMPUTE dummy=1. > 53 0 M> AGGREGATE /OUTFILE='C:\temp\AGGR.SAV' /BREAK=dummy /minval = >MIN( RR1s ) /maxval = MAX( RR1s ). > 54 0 M> MATCH FILES /FILE=* /TABLE='C:\Temp\AGGR.SAV' /BY dummy. > 55 0 M> COMPUTE RR1norm =( RR1s -minval)/(maxval - minval) > 56 0 M> . >!transf var=RR5s newvar=RR5norm. > 57 0 M> > 58 0 M> . > 59 0 M> COMPUTE dummy=1. > 60 0 M> AGGREGATE /OUTFILE='C:\temp\AGGR.SAV' /BREAK=dummy /minval = >MIN( RR5s ) /maxval = MAX( RR5s ). > >Error # 62 in column 20. Text: C:\temp\AGGR.SAV >The file is already in use. >Execution of this command stops. > 61 0 M> MATCH FILES /FILE=* /TABLE='C:\Temp\AGGR.SAV' /BY dummy. > 62 0 M> COMPUTE RR5norm =( RR5s -minval)/(maxval - minval) > 63 0 M> . >EXECUTE. > 64 0 M> EXECUTE. >SET MPRINT=no. > 65 0 M> SET MPRINT=no. > > >Mark Lavender >Application Architect and Developer >Finance IT > >===================== >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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
| Free forum by Nabble | Edit this page |
