Hi again A-J
I felt a bit bored with my present work, and I grabbed the opportunity of loosing some time fiddling with SPSS syntax. This works OK: DEFINE qwerty (). * This assumes an existing file *. DO IF ($casenum EQ 1). WRITE OUTFILE 'C:\Temp\Included.sps' /"DATA LIST FIXED/NoData 1-5(A)." /"BEGIN DATA" /"empty" /"END DATA.". END IF. * Sometimes I get an error saying the sps file is already in use and can't be included, the following two lines avoid it (with my excuses to Richard for using an execute!) *. CACHE. EXE. INCLUDE 'C:\Temp\Included.sps'. !ENDDEFINE. qwerty. Regards, Marta AjR> Sometimes I create a mini data set just to unload the AjR> current data set so I can rename it, change the AjR> attributes, move it, etc. But why does the syntax AjR> below not work? SPSS keeps giving the message 'waiting AjR> for more inline data'. Indenting, or putting AjR> everything on one line does not help. Any ideas? |
In reply to this post by Marta García-Granero
How about a simple NEW FILE command in place of the macro?
________________________________ From: SPSSX(r) Discussion on behalf of Marta García-Granero Sent: Fri 10/27/2006 9:33 AM To: [hidden email] Subject: Re: data list within a simple macro won't work Hi Albert-Jan (You shouldn't complain, my parents christened me using 4 names, fortunately, only one shows in my documents and ID card) Now, seriously: AjR> Sometimes I create a mini data set just to unload the AjR> current data set so I can rename it, change the AjR> attributes, move it, etc. But why does the syntax AjR> below not work? SPSS keeps giving the message 'waiting AjR> for more inline data'. Indenting, or putting AjR> everything on one line does not help. Any ideas? AjR> Albert-Jan AjR> (that guy so nice they named him twice ;-)) After a bit of T&E (Trial and Error, the best method to learn SPSS syntax sometimes - wry smile), I've found out this: The BEGIN DATA... END DATA part should be outside the macro, I'm afraid. I couldn't find any reference of that in the syntax guide (but that doesn't necessarily mean it isn't there, I've failed to notice some items in the past). This works OK, but is of little use: DEFINE !qwerty(). INPUT PROGRAM. DATA LIST FIXED/NoData 1-5 (A). END INPUT PROGRAM. EXECUTE. !ENDDEFINE. !qwerty. BEGIN DATA empty END DATA. I have tried to put the BEGIN DATA... END DATA inside a second macro to call them consecutevely, but it doesn't work either. The only thing I can concoct in my brain is to use WRITE OUTFILE to save to disk a file with the necessary commands, and then INCLUDE OR INSERT it. Don't blame the messenger... -- Regards, Dr. Marta García-Granero,PhD mailto:[hidden email] Statistician --- "It is unwise to use a statistical procedure whose use one does not understand. SPSS syntax guide cannot supply this knowledge, and it is certainly no substitute for the basic understanding of statistics and statistical thinking that is essential for the wise choice of methods and the correct interpretation of their results". (Adapted from WinPepi manual - I'm sure Joe Abrahmson will not mind) |
Try a more liberal sprinkling of periods!
define qwerty (). data list / empty 1-5 (a). begin data. empty end data. !enddefine. qwerty. end data. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Beadle, ViAnn Sent: Friday, October 27, 2006 9:51 AM To: [hidden email] Subject: Re: data list within a simple macro won't work How about a simple NEW FILE command in place of the macro? ________________________________ From: SPSSX(r) Discussion on behalf of Marta García-Granero Sent: Fri 10/27/2006 9:33 AM To: [hidden email] Subject: Re: data list within a simple macro won't work Hi Albert-Jan (You shouldn't complain, my parents christened me using 4 names, fortunately, only one shows in my documents and ID card) Now, seriously: AjR> Sometimes I create a mini data set just to unload the current data AjR> set so I can rename it, change the attributes, move it, etc. But AjR> why does the syntax below not work? SPSS keeps giving the message AjR> 'waiting for more inline data'. Indenting, or putting everything on AjR> one line does not help. Any ideas? AjR> Albert-Jan AjR> (that guy so nice they named him twice ;-)) After a bit of T&E (Trial and Error, the best method to learn SPSS syntax sometimes - wry smile), I've found out this: The BEGIN DATA... END DATA part should be outside the macro, I'm afraid. I couldn't find any reference of that in the syntax guide (but that doesn't necessarily mean it isn't there, I've failed to notice some items in the past). This works OK, but is of little use: DEFINE !qwerty(). INPUT PROGRAM. DATA LIST FIXED/NoData 1-5 (A). END INPUT PROGRAM. EXECUTE. !ENDDEFINE. !qwerty. BEGIN DATA empty END DATA. I have tried to put the BEGIN DATA... END DATA inside a second macro to call them consecutevely, but it doesn't work either. The only thing I can concoct in my brain is to use WRITE OUTFILE to save to disk a file with the necessary commands, and then INCLUDE OR INSERT it. Don't blame the messenger... -- Regards, Dr. Marta García-Granero,PhD mailto:[hidden email] Statistician --- "It is unwise to use a statistical procedure whose use one does not understand. SPSS syntax guide cannot supply this knowledge, and it is certainly no substitute for the basic understanding of statistics and statistical thinking that is essential for the wise choice of methods and the correct interpretation of their results". (Adapted from WinPepi manual - I'm sure Joe Abrahmson will not mind) |
John,
I thought the BEGIN DATA-END DATA command was not allow inside a macro (?). Has that changed with versions 14 and up? Thanks. Dominic Lusinchi Statistician Far West Research Statistical Consulting San Francisco, California 415-664-3032 www.farwestresearch.com -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bauer, John H. Sent: Friday, October 27, 2006 9:33 AM To: [hidden email] Subject: Re: data list within a simple macro won't work Try a more liberal sprinkling of periods! define qwerty (). data list / empty 1-5 (a). begin data. empty end data. !enddefine. qwerty. end data. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Beadle, ViAnn Sent: Friday, October 27, 2006 9:51 AM To: [hidden email] Subject: Re: data list within a simple macro won't work How about a simple NEW FILE command in place of the macro? ________________________________ From: SPSSX(r) Discussion on behalf of Marta García-Granero Sent: Fri 10/27/2006 9:33 AM To: [hidden email] Subject: Re: data list within a simple macro won't work Hi Albert-Jan (You shouldn't complain, my parents christened me using 4 names, fortunately, only one shows in my documents and ID card) Now, seriously: AjR> Sometimes I create a mini data set just to unload the current data AjR> set so I can rename it, change the attributes, move it, etc. But AjR> why does the syntax below not work? SPSS keeps giving the message AjR> 'waiting for more inline data'. Indenting, or putting everything on AjR> one line does not help. Any ideas? AjR> Albert-Jan AjR> (that guy so nice they named him twice ;-)) After a bit of T&E (Trial and Error, the best method to learn SPSS syntax sometimes - wry smile), I've found out this: The BEGIN DATA... END DATA part should be outside the macro, I'm afraid. I couldn't find any reference of that in the syntax guide (but that doesn't necessarily mean it isn't there, I've failed to notice some items in the past). This works OK, but is of little use: DEFINE !qwerty(). INPUT PROGRAM. DATA LIST FIXED/NoData 1-5 (A). END INPUT PROGRAM. EXECUTE. !ENDDEFINE. !qwerty. BEGIN DATA empty END DATA. I have tried to put the BEGIN DATA... END DATA inside a second macro to call them consecutevely, but it doesn't work either. The only thing I can concoct in my brain is to use WRITE OUTFILE to save to disk a file with the necessary commands, and then INCLUDE OR INSERT it. Don't blame the messenger... -- Regards, Dr. Marta García-Granero,PhD mailto:[hidden email] Statistician --- "It is unwise to use a statistical procedure whose use one does not understand. SPSS syntax guide cannot supply this knowledge, and it is certainly no substitute for the basic understanding of statistics and statistical thinking that is essential for the wise choice of methods and the correct interpretation of their results". (Adapted from WinPepi manual - I'm sure Joe Abrahmson will not mind) |
Whoops, it only worked because there was a fragment from a previous run; exactly the sort of thing that makes debugging macros so perilous.
In versions 14.0 and up one should of course use Programmability. I do this sort of thing with Python all the time. -----Original Message----- From: Dominic Lusinchi [mailto:[hidden email]] Sent: Friday, October 27, 2006 2:20 PM To: Bauer, John H.; [hidden email] Subject: RE: data list within a simple macro won't work John, I thought the BEGIN DATA-END DATA command was not allow inside a macro (?). Has that changed with versions 14 and up? Thanks. Dominic Lusinchi Statistician Far West Research Statistical Consulting San Francisco, California 415-664-3032 www.farwestresearch.com -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bauer, John H. Sent: Friday, October 27, 2006 9:33 AM To: [hidden email] Subject: Re: data list within a simple macro won't work Try a more liberal sprinkling of periods! define qwerty (). data list / empty 1-5 (a). begin data. empty end data. !enddefine. qwerty. end data. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Beadle, ViAnn Sent: Friday, October 27, 2006 9:51 AM To: [hidden email] Subject: Re: data list within a simple macro won't work How about a simple NEW FILE command in place of the macro? ________________________________ From: SPSSX(r) Discussion on behalf of Marta García-Granero Sent: Fri 10/27/2006 9:33 AM To: [hidden email] Subject: Re: data list within a simple macro won't work Hi Albert-Jan (You shouldn't complain, my parents christened me using 4 names, fortunately, only one shows in my documents and ID card) Now, seriously: AjR> Sometimes I create a mini data set just to unload the current data AjR> set so I can rename it, change the attributes, move it, etc. But AjR> why does the syntax below not work? SPSS keeps giving the message AjR> 'waiting for more inline data'. Indenting, or putting everything on AjR> one line does not help. Any ideas? AjR> Albert-Jan AjR> (that guy so nice they named him twice ;-)) After a bit of T&E (Trial and Error, the best method to learn SPSS syntax sometimes - wry smile), I've found out this: The BEGIN DATA... END DATA part should be outside the macro, I'm afraid. I couldn't find any reference of that in the syntax guide (but that doesn't necessarily mean it isn't there, I've failed to notice some items in the past). This works OK, but is of little use: DEFINE !qwerty(). INPUT PROGRAM. DATA LIST FIXED/NoData 1-5 (A). END INPUT PROGRAM. EXECUTE. !ENDDEFINE. !qwerty. BEGIN DATA empty END DATA. I have tried to put the BEGIN DATA... END DATA inside a second macro to call them consecutevely, but it doesn't work either. The only thing I can concoct in my brain is to use WRITE OUTFILE to save to disk a file with the necessary commands, and then INCLUDE OR INSERT it. Don't blame the messenger... -- Regards, Dr. Marta García-Granero,PhD mailto:[hidden email] Statistician --- "It is unwise to use a statistical procedure whose use one does not understand. SPSS syntax guide cannot supply this knowledge, and it is certainly no substitute for the basic understanding of statistics and statistical thinking that is essential for the wise choice of methods and the correct interpretation of their results". (Adapted from WinPepi manual - I'm sure Joe Abrahmson will not mind) |
In reply to this post by Marta García-Granero
At 10:45 AM 10/27/2006, Marta García-Granero wrote:
>I felt a bit bored with my present work, and I >grabbed the opportunity of loosing some time fiddling with SPSS syntax. > >DEFINE qwerty (). >* This assumes an existing file *. >DO IF ($casenum EQ 1). >WRITE OUTFILE 'C:\Temp\Included.sps' > /"DATA LIST FIXED/NoData 1-5(A)." > /"BEGIN DATA" > /"empty" > /"END DATA.". >END IF. >* Sometimes I get an error saying the sps file is already in use and > can't be included, the following two lines > avoid it (with my excuses > to Richard for using an execute!) *. >CACHE. >EXE. :-D Actually it shouldn't work without the EXECUTE (I don't know about the CACHE); this is one of the things EXECUTE is for. If you're writing a transformation whose purpose is NOT to transform the working file, but to output using PRINT, WRITE, or XSAVE, you need a procedure to force the program to be run even though you're not using its main output. To the rescue, EXECUTE, the procedure that does nothing... It should always have said the file was already in use. Once a transformation program opens an output file (destination of WRITE or XSAVE; or PRINT, if directed to a file), the file stays open until the transformation program ends, and shouldn't be available for opening by any other path. "It's not the planning, it's the execution." |
Free forum by Nabble | Edit this page |