Code not properly working on PASW DM book's example

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Code not properly working on PASW DM book's example

Luca Meyer-3
I am exercising with PASW and I have found a non-properly working code on a INPUT PROGRAM to read nested file example (pag. 47-48) in the "Programming and Data Management for PASW® Statistics 18"'s book.

The code is the following:

INPUT PROGRAM. 
COMPUTE #count=0. 
- DATA LIST FIXED END=#eof 
/#yr 1 (A) #reg 3(A) #person 25 (A). 
- DO IF #eof OR #count = 1000. 
- END FILE. 
- END IF. 
- DO IF #yr='Y'. 
- REREAD. 
- DATA LIST /Year 3-6. 
- LEAVE Year. 
- ELSE IF #reg='R'. 
- REREAD. 
- DATA LIST / Region 5-15 (A). 
- LEAVE Region. 
- ELSE IF #person='P' AND UNIFORM(1000) < 500. 
- REREAD. 
- DATA LIST / SalesRep 7-17 (A) Sales 20-23. 
- END CASE. 
- COMPUTE #count=#count+1. 
- END IF. 
END INPUT PROGRAM.

BEGIN DATA 
Y 2002
  R Chicago 
      Jones        900  P 
      Gregory      400  P
  R Baton Rouge 
      Rodriguez    300  P
      Smith        333  P
      Grau         100  P
END DATA.

The claim is that the reading will stop at the end of file or when 1000 records are read, but I believe the #count is updated within another DO IF - END IF procedure and the 1.000 limit does not apply. 

I have tested my assumption setting #count=3 and removing the random selection but the software reads all 5 cases. I have tried to insert an "AND #count<=3" within every DO IF and ELSE IF statement within the second DO IF ... END IF procedure but I always have 5 cases.

How would you correct the syntax to have only 3 cases imported?

Thanks,
Luca

Luca Meyer
www.lucameyer.com
PASW Statistics v. 18.0.2 (2-apr-2010)
R version 2.9.2 (2009-08-24)
Mac OS X 10.6.3 (10D573) - kernel Darwin 10.3.0






Reply | Threaded
Open this post in threaded view
|

Re: Code not properly working on PASW DM book's example

Rick Oliver-3

Oops. Instead of:

COMPUTE #count=0.

try:

NUMERIC #count (f8).

I think the former was resetting #count to 0 for each case. You need to declare the scratch variable for use in the subsequent COMPUTE #count=#count+1, but you don't need to initialize it to 0, because scratch variables are automatically initialized to 0 -- and in this case explicitly setting it to 0 was causing the condition to never be met. (For testing purposes, you might want to remove the random UNIFORM condition.)


From: Luca Meyer <[hidden email]>
To: [hidden email]
Date: 05/11/2010 03:17 AM
Subject: Code not properly working on PASW DM book's example
Sent by: "SPSSX(r) Discussion" <[hidden email]>





I am exercising with PASW and I have found a non-properly working code on a INPUT PROGRAM to read nested file example (pag. 47-48) in the "Programming and Data Management for PASW® Statistics 18"'s book.

The code is the following:

INPUT PROGRAM.
COMPUTE #count=0.
- DATA LIST FIXED END=#eof
/#yr 1 (A) #reg 3(A) #person 25 (A).
- DO IF #eof OR #count = 1000.
- END FILE.
- END IF.
- DO IF #yr='Y'.
- REREAD.
- DATA LIST /Year 3-6.
- LEAVE Year.
- ELSE IF #reg='R'.
- REREAD.
- DATA LIST / Region 5-15 (A).
- LEAVE Region.
- ELSE IF #person='P' AND UNIFORM(1000) < 500.
- REREAD.
- DATA LIST / SalesRep 7-17 (A) Sales 20-23.
- END CASE.
- COMPUTE #count=#count+1.
- END IF.
END INPUT PROGRAM.

BEGIN DATA
Y 2002
  R Chicago
      Jones        900  P
      Gregory      400  P
  R Baton Rouge
      Rodriguez    300  P
      Smith        333  P
      Grau         100  P
END DATA.

The claim is that the reading will stop at the end of file or when 1000 records are read, but I believe the #count is updated within another DO IF - END IF procedure and the 1.000 limit does not apply.

I have tested my assumption setting #count=3 and removing the random selection but the software reads all 5 cases. I have tried to insert an "AND #count<=3" within every DO IF and ELSE IF statement within the second DO IF ... END IF procedure but I always have 5 cases.

How would you correct the syntax to have only 3 cases imported?

Thanks,
Luca

Luca Meyer
www.lucameyer.com
PASW Statistics v. 18.0.2 (2-apr-2010)

R version 2.9.2 (2009-08-24)
Mac OS X 10.6.3 (10D573) - kernel Darwin 10.3.0








Reply | Threaded
Open this post in threaded view
|

Re: Code not properly working on PASW DM book's example

David Marso
Administrator
In reply to this post by Luca Meyer-3
INPUT PROGRAM.
NUMERIC #count .
- DATA LIST FIXED END=#eof /#yr 1 (A) #reg 3(A) #person 25 (A).
- DO IF #eof OR #count = 3.
-  END FILE.
- ELSE IF #yr='Y'.
-  REREAD.
-  DATA LIST /Year 3-6.
-  LEAVE Year.
- ELSE IF #reg='R'.
-  REREAD.
-  DATA LIST / Region 5-15 (A).
-  LEAVE Region.
- ELSE IF #person='P'.
-  REREAD.
-  DATA LIST / SalesRep 7-17 (A) Sales 20-23.
-  END CASE.
-  COMPUTE #count=#count+1.
- END IF.
END INPUT PROGRAM.

On Tue, 11 May 2010 10:12:05 +0200, Luca Meyer <[hidden email]> wrote:

>I am exercising with PASW and I have found a non-properly working code on a
INPUT PROGRAM to read nested file example (pag. 47-48) in the "Programming
and Data Management for PASW� Statistics 18"'s book.

>
>The code is the following:
>
>INPUT PROGRAM.
>COMPUTE #count=0.
>- DATA LIST FIXED END=#eof
>        /#yr 1 (A) #reg 3(A) #person 25 (A).
>- DO IF #eof OR #count = 1000.
>-       END FILE.
>- END IF.
>- DO IF #yr='Y'.
>-       REREAD.
>-       DATA LIST /Year 3-6.
>-       LEAVE Year.
>- ELSE IF #reg='R'.
>-       REREAD.
>-       DATA LIST / Region 5-15 (A).
>-       LEAVE Region.
>- ELSE IF #person='P' AND UNIFORM(1000) < 500.
>-       REREAD.
>-       DATA LIST / SalesRep 7-17 (A) Sales 20-23.
>-       END CASE.
>-       COMPUTE #count=#count+1.
>- END IF.
>END INPUT PROGRAM.
>
>BEGIN DATA
>Y 2002
>  R Chicago
>      Jones        900  P
>      Gregory      400  P
>  R Baton Rouge
>      Rodriguez    300  P
>      Smith        333  P
>      Grau         100  P
>END DATA.
>
>The claim is that the reading will stop at the end of file or when 1000
records are read, but I believe the #count is updated within another DO IF -
END IF procedure and the 1.000 limit does not apply.
>
>I have tested my assumption setting #count=3 and removing the random
selection but the software reads all 5 cases. I have tried to insert an "AND
#count<=3" within every DO IF and ELSE IF statement within the second DO IF
... END IF procedure but I always have 5 cases.

>
>How would you correct the syntax to have only 3 cases imported?
>
>Thanks,
>Luca
>
>Luca Meyer
>www.lucameyer.com
>PASW Statistics v. 18.0.2 (2-apr-2010)
>R version 2.9.2 (2009-08-24)
>Mac OS X 10.6.3 (10D573) - kernel Darwin 10.3.0
>
>
>
>
>
>
>

=====================
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?"