```Date: Wed, 12 Sep 2001 10:41:05 +0100 Reply-To: Paul Mcgeoghan Sender: "SPSSX(r) Discussion" From: Paul Mcgeoghan Subject: Re: looping syntax ---> automated solution (What else were you expecting?) Comments: To: rlevesque@videotron.ca Content-Type: text/plain; charset=US-ASCII Raynald, Thanks, works a treat. Saved me hours of work once again. Paul >>> "Raynald Levesque" 09/12/01 02:05am >>> Hi Paul The LOOP syntax does not work because only transformation commands are allowed within a loop (the NPAR TESTS is a procedure, not a transformation). The solution to this type of problem is actually a particular case of a general solution I posted to the list on August 23rd with the subject "Use of array to streamline code". The particular case is a bit simpler than the general solution but, yet, it is fairly complex code. So here is the automated solution to your problem. * (Q) Find all combinations of n items out of m items then apply NPAR TESTS to each of these combinations. * (A) by rlevesque@videotron.ca 2001/09/11; SPSS Dedicated web site http://pages.infinit.net/rlevesqu/index.htm. * Note: This is a COMPLEX syntax but it is very EASY TO USE. See the example at the end. SET MPRINT=no. */////////////////////////////. DEFINE !combine (n=!TOKENS(1) /items=!CMDEND). /* Find all combinations of n items out of m items*/ /* Sept 11,2001 rlevesque@videotron.ca */ * Count number of variables. !LET !nb=!NULL !DO !cnt !IN (!items) !LET !nb=!CONCAT(!nb,!BLANK(1)) !DOEND !LET !m=!LENGTH(!nb) NEW FILE. INPUT PROGRAM. LOOP i=1 TO !n. END CASE. END LOOP. END FILE. END INPUT PROGRAM. LIST. !LET !list=!NULL !DO !cnt=1 !TO !n !LET !list=!CONCAT(!list," ","j",!cnt) !DOEND COMPUTE n=!n. * Calculate variable names for LOOP of the next WRITE command *. STRING cntname cntbeg(A8). COMPUTE cntname=CONCAT('j',LTRIM(STRING(i,F8.0))). * Calculate first parameter for the LOOP of the next WRITE command *. DO IF i=1. COMPUTE cntbeg="1". ELSE. COMPUTE cntbeg=CONCAT('j',LTRIM(STRING(i-1,F8.0))," + 1"). END IF. * Calculate second parameter for the LOOP of the next WRITE command *. COMPUTE k=!m - !n + i. FORMATS i k n(F8.0). STRING quote(A1) strlist(A255). COMPUTE quote='"'. COMPUTE strlist=!QUOTE(!list). * Write the syntax file which will store all the combinations in the list.txt file*. WRITE OUTFILE "c:\temp\macro.sps" /"LOOP "cntname"="cntbeg" TO "k".". DO IF i=!n. + WRITE OUTFILE "c:\temp\macro.sps" /"WRITE OUTFILE "quote"c:\temp\list.txt"quote "/" strlist "." . + LOOP cnt=1 TO !n. + WRITE OUTFILE "c:\temp\macro.sps" /"END LOOP.". + END LOOP. + WRITE OUTFILE "c:\temp\macro.sps" /"EXECUTE.". END IF. EXECUTE. INCLUDE FILE="c:\temp\macro.sps". /* Convert data from list.txt to the corresponding sav file */. DATA LIST FILE='c:\temp\list.txt' LIST /!list. SAVE OUTFILE='c:\temp\list1.sav'. /* Eliminate duplicates */. SORT CASES BY ALL. MATCH FILES FILE=* /BY=ALL /FIRST=first. SELECT IF first. SAVE OUTFILE='c:\temp\all combinations.sav'. /* Find name of last variables */ !DO !var !IN (!items) !LET !lastone=!var !DOEND VECTOR vnames(!m A8). !LET !cnt=!BLANK(1) /* Create variables containing the names of the items variables */ !DO !var !IN (!items) COMPUTE vnames(!LEN(!cnt))=!QUOTE(!var). !LET !cnt=!CONCAT(!cnt,!BLANK(1)) !DOEND /* Construct the string containing the list of combinations */. STRING items(A255). VECTOR j=j1 TO !CONCAT('j',!n) /ind=vnames1 TO !CONCAT('vnames',!m). COMPUTE nvar=NVALID(j1 TO !CONCAT('j',!n)). LOOP cnt=1 TO nvar. + COMPUTE items=CONCAT(RTRIM(items)," ",vnames(j(cnt))). END LOOP. * Write the syntax file which will call the macro for each desired combination of variables. WRITE OUTFILE='c:\temp\mymacro.sps' /'!kendal 'items'.'. EXECUTE. !ENDDEFINE. *////////////////////////////. *////////////////////////////. DEFINE !kendal (!POS=!CMDEND) NPAR TESTS /KENDALL = !1 /MISSING LISTWISE. !ENDDEFINE. *////////////////////////////. *************************. * EXAMPLES OF USE. *************************. SET MPRINT=yes. * write syntax file which will calculate Kendall for every combinations of 2 variables. !combine n=2 items=educ jobcat jobtime prevexp minority. GET FILE='c:\program files\spss\employee data.sav'. *** Next line does the job ***. INCLUDE FILE='c:\temp\mymacro.sps'. *********************. * Comments on above example. *********************. All you have to do is replace the line !combine n=2 items=educ jobcat jobtime prevexp minority. by the list of the 50 variables in your file then replace the line GET FILE='c:\program files\spss\employee data.sav'. by a line loading you data file. Everything will be done automatically for you. In your case, you have only 50 variables it is not a huge task to list all of those in macro call. Assuming you have hundreds of consecutive variables, you could use the macro defined in the syntax file "Define List of Variables between two variables.SPS" which is in the "Macro Gems" section of my web site. With this macro, you would only have to list the first and last variables in the macro call. Have fun! Raynald Levesque rlevesque@videotron.ca Visit My SPSS Pages: http://pages.infinit.net/rlevesqu/index.htm -----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]On Behalf Of Paul Mcgeoghan Sent: Monday, September 10, 2001 9:31 AM To: SPSSX-L@LISTSERV.UGA.EDU Subject: looping syntax Hi, I posted this query before recently but didn't get any response so I will try and phrase it differently. Using the following syntax for k-related samples Kendall test: NPAR TESTS /KENDALL = A B /MISSING LISTWISE. I would get a value for Kendall's Coefficient of Concordance. If I have variables A B C adjacent to each other in the data and wish to get have three separate Kendall's values for comparisons A B A C B C I would need to do the same syntax three times replacing A B with A C and B C respectively. (in the real data, there are 50 variables not 3) Looking at the DO REPEAT syntax and LOOP syntax, I am not to sure how to proceed. Any one any tips on how to start, I think I need to use DO REPEAT to carry out what I want. Thanks in advance, Paul ```

Back to: Top of message | Previous page | Main SPSSX-L page