LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2005)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 29 Sep 2005 16:34:57 +0200
Reply-To:   Marta García-Granero <biostatistics@terra.es>
Sender:   "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:   Marta García-Granero <biostatistics@terra.es>
Organization:   Asesoría Bioestadística
Subject:   Re: Finding information on +
In-Reply-To:   <E08B564BAA29FE4F8EC8BAF42FE0A01F126757@bubsex02.cen.csin.cz>
Content-Type:   text/plain; charset=ISO-8859-15

Hi Martin

Just an example to add a visual explanation to Jan's answer.

Consider the following code (it's been extracted from a longer MATRIX program, and it has no sense now):

LOOP i=1 TO ndata. LOOP j=1 TO nvars-1. LOOP k=j TO nvars. DO IF data(i,j) GT data(i,k). COMPUTE diagmat(j,k)=diagmat(j,k)+1. ELSE IF data(i,j) LT data(i,k). COMPUTE diagmat(k,j)=diagmat(k,j)+1. END IF. END LOOP. END LOOP. END LOOP.

It has 3 nested loops and a comple DO IF/ELSE IF/END IF clause inside. Trying to debug it is hard (any unclosed loop?...). Look at the same code, "beautified" (quoting Jan's expression):

LOOP i=1 TO ndata. - LOOP j=1 TO nvars-1. - LOOP k=j TO nvars. - DO IF data(i,j) GT data(i,k). - COMPUTE diagmat(j,k)=diagmat(j,k)+1. - ELSE IF data(i,j) LT data(i,k). - COMPUTE diagmat(k,j)=diagmat(k,j)+1. - END IF. - END LOOP. - END LOOP. END LOOP.

Now, I can clearly see in which looping level I am at each line, and that the COMPUTE statments are inside the DO IF/END IF clause (and that the DO IF/END IF is inside the third LOOP).

Both codes are essentially the same (both will run OK and give exctly the same result), but the second is easier to understand and debug.

BTW, I don't use +, only -, because when I installed SPSS 12, I found that running code using INCLUDE caused a syntax error whenever a + was used for indenting the code. Although that problem was fixed after installing a patch, I still prefer to use - instead of +, just in case my code is run in unpatched SPSS 12.

Cheers

Marta

SJ> the + sign is simply beautifying the code. One of the conventions of SJ> writing SPSS commands does not allow you to start a new command line SJ> with a blank, so use + or - or . instead of it if you wish to indent the SJ> line.

SJ> Dear list. My help command on SPSS 13.0 is not functioning and I SJ> am trying to get a handle on the use of the + sign in a do if SJ> loop. Is it simply allowing one to use a do if within a do if? SJ> thanks, martin sherman

SJ> do if nmiss(pcl_b, pcl_c, pcl_d) eq 0. SJ> + Do if (pcl_b ge 1 and pcl_c ge 3 and pcl_d ge 2). SJ> + compute pcl_dsm3=1. SJ> + else if (pcl_b lt 1 or pcl_c lt 3 or pcl_d lt 2). SJ> + compute pcl_dsm3=0. SJ> + end if. SJ> Else. SJ> Compute pcl_dsm3 eq 9. SJ> End if.


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