I’m working on a little tiny macro problem and have the following code already written. I want to do some checking. I run the step 1 line, I select and intend to run the step 2 line block. Instead, every thing below the step 1 line is selected
and executed. I repeated this several times so I do not believe it is my error. So, 1) what is the story of why this functioning is a good thing? 2) How do I avoid this error in program functioning? Without rearranging the code—because that will work! Jump in somebody from spss! Gene Maguin get file='u:\temp\Example.sav'. << select, execute, step 1. set mtindex=123456. define !resample(). * looping. !do !i=1 to 3. get file='u:\temp\Example.sav'. do if (e eq 3). << select this group of 4 lines, intended execute, step 2. + sample 1000 from 99000. end if. frequencies e. oms select tables/if subtypes="report"/destination format=sav/ outfile='u:\temp\gbye.sav' viewer=no. means g by e/cells=mean. oms select tables/if subtypes="report"/destination format=sav/ outfile='u:\temp\gbyv.sav' viewer=no. means g by v/cells=mean. oms select tables/if subtypes="report"/destination format=sav/ outfile='u:\temp\vbye.sav' viewer=no. means v by e/cells=mean. |
I can't reproduce this behavior from the description, but you have an unclosed macro definition and an unclosed do if block, so what is the poor syntax editor to do? On Wed, Jan 6, 2016 at 3:53 PM, Maguin, Eugene <[hidden email]> wrote:
|
Administrator
|
In addition to the missing !ENDDEFINE statement, IF you intend this to be a !DO then you need !TO rather than TO. Also, I'm not sure what SAMPLE does within the scope of a DO IF block (not going to bother to find out empirically nor do any RTFM thing -after 1 AM EST-). Maybe you want SELECT IF instead. I note that you are using MEANS with OMS for something which is trivially achieved with AGGREGATE. Maybe spell out the big picture (what exactly are you trying to do???) and someone will suggest a more efficient path. I personally would do the whole thing (if I understand what you are trying to do ) in MATRIX with a few lines of code.
Finally, you should test your syntax outside of a macro first ie. remove the DEFINE statement, test, test some more....iterate until fixed, parameterize where appropriate, add DEFINE !ENDDEFINE around working code , test some more... put into production.
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?" |
In reply to this post by Jon Peck
Jon, David,
Thank you both for replying.
Jon, your reply first.
Are you saying that if you create a little file (N=100000, e=1 (n=500), e=2 (n=500), e=3 (n=99K)), which I call Example, then put the code I sent in spss and
in two separate steps, select/execute the line marked ‘step 1’ and in step 2 select/execute the block of 4 lines marked ‘step 2’, then all the lines following the step 1 line down to and including the last omsend line do not execute? I hope I said that clearly.
If not, then I’ll say it this way. Are you saying that for you selecting and executing the block of lines marked as ‘step 2’ does not also cause the execution of all lines beginning with and following the ‘set mtindex=1232456.’?
I tried it again this morning and I got the same result as yesterday.
My expectation is that the selected lines and ONLY the selected lines are executed. I want to be sarcastic about this but I won’t be. I think I have noticed this before and commented on it and a now-retired female colleague of yours, whose name I forget, but who frequently answered GPL questions
had something to say about this. I think she said that this behavior was/is a design element of the editor. However, I also notice that it (the editor) doesn’t usually work this way because not infrequently I’ll open a syntax file, execute the get file command
located at the top of the file and then jump down 50, 100, 200 lines and select and execute code from that point onwards and the ‘x’ many lines of code above that point are not re-executed.
David, your reply. Big picture. I did some analyses involving the procedures embedded in the oms statements using a kind of large, but unbalanced dataset (similar to the ‘little
file’ I describe above). A reviewer asked if we would comment on the results if the e=3 group were equal in size to e=1+e=2. Easy enough to do. (Embedding a sample command in a do if block is actually shown in the FM.) But one draw is just one draw. Better,
I think, to do 30 to 50 draws and talk about the effect size/coefficient distributions of each result. Thus the macro. I understand your point about aggregate but I need to aggregate by two different variables, e and v, plus I need the regression. I didn’t
think (and don’t usually think) of matrix. I’m not asking you to show code but could this be done in matrix?
The editor business aside, I have a question about how the random number function works. There’s a default seed, which I changed. I assume (correctly?, incorrectly?)
that when a rv.xxx function is called repeatedly, something evolves so that the generated random number also evolves and is not necessarily the same. (I freely admit that I don’t understand how the rv.xxx functions work in spss.) Here, I will loop through
the sample command 30 times and I want each pass through to select a random set of cases for the e=3 group. So, on each execution of sample will the same value of the seed be used, thereby resulting in the same set of cases being selected? If that is true,
is there another way to alter the seed other than doing macro arithmetic, which, I think, is, politely stated, involved.
Gene Maguin From: Jon Peck [mailto:[hidden email]]
I can't reproduce this behavior from the description, but you have an unclosed macro definition and an unclosed do if block, so what is the poor syntax editor to do? On Wed, Jan 6, 2016 at 3:53 PM, Maguin, Eugene <[hidden email]> wrote:
-- Jon K Peck |
Re the random numbers it sounds like you have it right. Example below.
**************************************************. DATASET CLOSE ALL. OUTPUT CLOSE ALL. DATA LIST FREE / X. BEGIN DATA 1 2 3 4 5 6 7 8 9 10 END DATA. DEFINE !RandSamp () !DO !I = 1 !TO 3 TEMPORARY. SAMPLE 2 FROM 10. LIST X. !DOEND !ENDDEFINE. SET SEED 10. !RandSamp. *2,10|3,9|5,8. *This is different. !RandSamp. *8,9|3,10|4,7. *This is same as orig. SET SEED 10. !RandSamp. *2,10|3,9|5,8. DEFINE !RandSamp2 () !DO !I = 1 !TO 3 SET SEED 11. TEMPORARY. SAMPLE 2 FROM 10. LIST X. !DOEND !ENDDEFINE. *This produces same for each iteration. !RandSamp2. *3,9|3,9|3,9. **************************************************. It seems to me your hang up with the editor is it wants to run whole DO-IF blocks and whole DEFINE-!ENDDEFINE blocks. Alittle annoying I guess but not the end of the world. |
Administrator
|
In reply to this post by Maguin, Eugene
"plus I need the regression. I didn’t think (and don’t usually think) of matrix. I’m not asking you to show code but could this be done in matrix?"
DATA LIST FREE / x y. BEGIN DATA 1 2 3 4 4 2 5 6 3 7 7 2 8 6 5 3 5 4 7 7 8 7 END DATA. REGRESSION DEP y / METHOD ENTER x. * Bo=2.500, B1= .402. MATRIX. GET x / VARIABLES x /FILE *. GET y / VARIABLES y /FILE *. COMPUTE x={MAKE (NRow(X),1,1),x}. COMPUTE b=GINV(T(x)*x)*(T(x)*y). PRINT b. END MATRIX. *B * 2.500000000 * .401785714
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?" |
In reply to this post by Maguin, Eugene
->
plus
I need the regression. I didn’t think (and don’t usually think)
of matrix. I’m not asking you to show code but could this be
done in matrix?
Gene, you can do many, many things in MATRIX. Thanks to people like David or myself who have been exploring its possibilities. Check, for example, collection of my matrix functions on http://www.spsstools.net/en/KO-spssmacros, where linear regression coefficients estimation is also present. ===================== 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 |
In reply to this post by Maguin, Eugene
I'm away from my computer, but the SE needs to run complete commands, and having an open macro is likely to confuse things. In fact, macros are not fully supported in the SE: the editor does not have an embedded macro processor.
As for the random numbers, Andy is right. The sequence does not reset until you run SET SEED. You might want to use the same starting point at the top for repeatability. On Thursday, January 7, 2016, Maguin, Eugene <[hidden email]> wrote:
-- ===================== 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 |
Free forum by Nabble | Edit this page |