DO REPEAT not allowed inside DO IF

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

DO REPEAT not allowed inside DO IF

John F Hall

Problem solved by Mario Giesel

Just what was needed.  Thanks Mario.

 

Some initial problems with Word document sent to Nabble.  Converted to pdf and resent to Mario, Rich, Jon and Gene

Full details on Nabble

http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?new_topic

 

Final macro syntax:

 

 

* Encoding: UTF-8.

* -----------------------------.

* Encoding: UTF-8.

DEFINE !format (!POS !CMDEND)

PRESERVE.

SET PRINTBACK = ON MPRINT = ON.

!DO !v  !IN (!1) /* Loop over format arguments*/

 

!LET !XX1 = !CONCAT(!v,"1")

!LET !XX1a = !CONCAT(!v,"1a")

!LET !XX1b = !CONCAT(!v,"1b")

!LET !XX1c = !CONCAT(!v,"1c")

!LET !XX = !v

 

!IF (!v = 'tv') !THEN !LET !wantXX = wanttv !IFEND

!IF (!v = 'phone') !THEN !LET !wantXX = wantphn !IFEND

!IF (!v = 'car') !THEN !LET !wantXX = wantcar !IFEND

!IF (!v = 'fridge') !THEN !LET !wantXX = wantfrg !IFEND

!IF (!v = 'washmach') !THEN !LET !wantXX = wantwash !IFEND

!IF (!v = 'recordpl') !THEN !LET !wantXX = wantrpl !IFEND

!IF (!v = 'cheating') !THEN !LET !wantXX = wantch !IFEND

 

count !XX1a = !XX (2) !wantXX (1)

/!XX1b = !XX (2) !wantXX (2)

/!XX1c = !XX (2) !wantXX (3).

frequencies !XX1a !XX1b !XX1c.

compute !XX1=!XX.

do if

    !XX1a=2.

compute !XX1 =2.

else if

   !XX1b=2.

compute !XX1 =3.

else if

   !XX1c=2.

compute !XX1 =4.

end if.

formats !XX1a to !XX1 (n1).

variable labels !XX1 !QUOTE(!CONCAT('Have/want ', !XX)).

value labels !XX1

1 'Yes, already have' 2 'No, but want' 3 "No, but don't want" 4 "No but don't know if want".

 

!DOEND

RESTORE.

!ENDDEFINE.

 

freq tv1 phone1 car1 fridge1 washmach1 recordpl1 cheating1.

 

 

tv1 Have/want tv

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1 Yes, already have

1185

83.7

83.9

83.9

2 No, but want

65

4.6

4.6

88.5

3 No, but don't want

161

11.4

11.4

99.9

4 No but don't know if want

2

.1

.1

100.0

Total

1413

99.9

100.0

 

Missing

System

2

.1

 

 

Total

1415

100.0

 

 

 

phone1 Have/want phone

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1 Yes, already have

322

22.8

22.8

22.8

2 No, but want

242

17.1

17.1

39.9

3 No, but don't want

827

58.4

58.5

98.4

4 No but don't know if want

23

1.6

1.6

100.0

Total

1414

99.9

100.0

 

Missing

System

1

.1

 

 

Total

1415

100.0

 

 

 

car1 Have/want car

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1 Yes, already have

540

38.2

38.2

38.2

2 No, but want

383

27.1

27.1

65.4

3 No, but don't want

477

33.7

33.8

99.2

4 No but don't know if want

12

.8

.8

100.0

Total

1412

99.8

100.0

 

Missing

System

3

.2

 

 

Total

1415

100.0

 

 

 

fridge1 Have/want fridge

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1 Yes, already have

495

35.0

35.0

35.0

2 No, but want

504

35.6

35.7

70.7

3 No, but don't want

397

28.1

28.1

98.8

4 No but don't know if want

17

1.2

1.2

100.0

Total

1413

99.9

100.0

 

Missing

System

2

.1

 

 

Total

1415

100.0

 

 

 

 

washmach1 Have/want washmach

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1 Yes, already have

702

49.6

49.6

49.6

2 No, but want

258

18.2

18.2

67.9

3 No, but don't want

441

31.2

31.2

99.1

4 No but don't know if want

13

.9

.9

100.0

Total

1414

99.9

100.0

 

Missing

System

1

.1

 

 

Total

1415

100.0

 

 

 

recordpl1 Have/want recordpl

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1.00 Yes, already have

512

36.2

36.2

36.2

2.00 No, but want

150

10.6

10.6

46.8

3.00 No, but don't want

733

51.8

51.8

98.7

4.00 No but don't know if want

19

1.3

1.3

100.0

Total

1414

99.9

100.0

 

Missing

System

1

.1

 

 

Total

1415

100.0

 

 

 

 

cheating1 Have/want cheating

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1 Yes, already have

83

5.9

5.9

5.9

2 No, but want

525

37.1

37.2

43.0

3 No, but don't want

774

54.7

54.8

97.8

4 No but don't know if want

31

2.2

2.2

100.0

Total

1413

99.9

100.0

 

Missing

System

2

.1

 

 

Total

1415

100.0

 

 

 

Will now apply to Runciman's second list of items only the better off can afford:

 

(These are as in the UKDS documentation: http://doc.ukdataservice.ac.uk/doc/28/mrdoc/pdf/sn28userguide.pdf, pp17-18)

(For exact wording of questions, see the facsimile questionnaire in the actual book)

 

Q.13a: Have you already got a house of your own?

IF NO: Q.13b: Do you want your own house?

 

Q.13a: Have you already got a fur coat for your wife?

IF NO: Q.13b: Do you want a fur coat for wife?

 

Q.13a: Do you already go abroad for holidays?

IF NO: Q.13b: Would you like foreign holiday travel?

 

Q.13a: Do you have a spare bedroom for visitors?

IF NO: Q.13b: Would you like a spare bedroom for visitors?

 

Q.13a: Do you already use first class travel?

IF NO: Q.13b: Would you like to travel first class?

 

Q.13a: Do you use private education for your children?

IF NO: Q.13b: Would you like private education for your children?

 

 

 

 

 

===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: DO REPEAT not allowed inside DO IF

John F Hall
Consumer_goods.pdf
<http://spssx-discussion.1045642.n5.nabble.com/file/t27438/Consumer_goods.pdf>  



--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: DO REPEAT not allowed inside DO IF

Brian Dates
In reply to this post by John F Hall
John,

Thanks for posting the solution. This is very helpful. I wish everyone would do the same.

B

Brian G. Dates, M.A.
Consultant in Program Evaluation, Research, and Statistics
248-229-2865


On Sat, Jan 9, 2021 at 11:55 AM Joihn F Hall <[hidden email]> wrote:

Problem solved by Mario Giesel

Just what was needed.  Thanks Mario.

 

Some initial problems with Word document sent to Nabble.  Converted to pdf and resent to Mario, Rich, Jon and Gene

Full details on Nabble

http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?new_topic

 

Final macro syntax:

 

 

* Encoding: UTF-8.

* -----------------------------.

* Encoding: UTF-8.

DEFINE !format (!POS !CMDEND)

PRESERVE.

SET PRINTBACK = ON MPRINT = ON.

!DO !v  !IN (!1) /* Loop over format arguments*/

 

!LET !XX1 = !CONCAT(!v,"1")

!LET !XX1a = !CONCAT(!v,"1a")

!LET !XX1b = !CONCAT(!v,"1b")

!LET !XX1c = !CONCAT(!v,"1c")

!LET !XX = !v

 

!IF (!v = 'tv') !THEN !LET !wantXX = wanttv !IFEND

!IF (!v = 'phone') !THEN !LET !wantXX = wantphn !IFEND

!IF (!v = 'car') !THEN !LET !wantXX = wantcar !IFEND

!IF (!v = 'fridge') !THEN !LET !wantXX = wantfrg !IFEND

!IF (!v = 'washmach') !THEN !LET !wantXX = wantwash !IFEND

!IF (!v = 'recordpl') !THEN !LET !wantXX = wantrpl !IFEND

!IF (!v = 'cheating') !THEN !LET !wantXX = wantch !IFEND

 

count !XX1a = !XX (2) !wantXX (1)

/!XX1b = !XX (2) !wantXX (2)

/!XX1c = !XX (2) !wantXX (3).

frequencies !XX1a !XX1b !XX1c.

compute !XX1=!XX.

do if

    !XX1a=2.

compute !XX1 =2.

else if

   !XX1b=2.

compute !XX1 =3.

else if

   !XX1c=2.

compute !XX1 =4.

end if.

formats !XX1a to !XX1 (n1).

variable labels !XX1 !QUOTE(!CONCAT('Have/want ', !XX)).

value labels !XX1

1 'Yes, already have' 2 'No, but want' 3 "No, but don't want" 4 "No but don't know if want".

 

!DOEND

RESTORE.

!ENDDEFINE.

 

freq tv1 phone1 car1 fridge1 washmach1 recordpl1 cheating1.

 

 

tv1 Have/want tv

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1 Yes, already have

1185

83.7

83.9

83.9

2 No, but want

65

4.6

4.6

88.5

3 No, but don't want

161

11.4

11.4

99.9

4 No but don't know if want

2

.1

.1

100.0

Total

1413

99.9

100.0

 

Missing

System

2

.1

 

 

Total

1415

100.0

 

 

 

phone1 Have/want phone

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1 Yes, already have

322

22.8

22.8

22.8

2 No, but want

242

17.1

17.1

39.9

3 No, but don't want

827

58.4

58.5

98.4

4 No but don't know if want

23

1.6

1.6

100.0

Total

1414

99.9

100.0

 

Missing

System

1

.1

 

 

Total

1415

100.0

 

 

 

car1 Have/want car

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1 Yes, already have

540

38.2

38.2

38.2

2 No, but want

383

27.1

27.1

65.4

3 No, but don't want

477

33.7

33.8

99.2

4 No but don't know if want

12

.8

.8

100.0

Total

1412

99.8

100.0

 

Missing

System

3

.2

 

 

Total

1415

100.0

 

 

 

fridge1 Have/want fridge

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1 Yes, already have

495

35.0

35.0

35.0

2 No, but want

504

35.6

35.7

70.7

3 No, but don't want

397

28.1

28.1

98.8

4 No but don't know if want

17

1.2

1.2

100.0

Total

1413

99.9

100.0

 

Missing

System

2

.1

 

 

Total

1415

100.0

 

 

 

 

washmach1 Have/want washmach

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1 Yes, already have

702

49.6

49.6

49.6

2 No, but want

258

18.2

18.2

67.9

3 No, but don't want

441

31.2

31.2

99.1

4 No but don't know if want

13

.9

.9

100.0

Total

1414

99.9

100.0

 

Missing

System

1

.1

 

 

Total

1415

100.0

 

 

 

recordpl1 Have/want recordpl

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1.00 Yes, already have

512

36.2

36.2

36.2

2.00 No, but want

150

10.6

10.6

46.8

3.00 No, but don't want

733

51.8

51.8

98.7

4.00 No but don't know if want

19

1.3

1.3

100.0

Total

1414

99.9

100.0

 

Missing

System

1

.1

 

 

Total

1415

100.0

 

 

 

 

cheating1 Have/want cheating

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1 Yes, already have

83

5.9

5.9

5.9

2 No, but want

525

37.1

37.2

43.0

3 No, but don't want

774

54.7

54.8

97.8

4 No but don't know if want

31

2.2

2.2

100.0

Total

1413

99.9

100.0

 

Missing

System

2

.1

 

 

Total

1415

100.0

 

 

 

Will now apply to Runciman's second list of items only the better off can afford:

 

(These are as in the UKDS documentation: http://doc.ukdataservice.ac.uk/doc/28/mrdoc/pdf/sn28userguide.pdf, pp17-18)

(For exact wording of questions, see the facsimile questionnaire in the actual book)

 

Q.13a: Have you already got a house of your own?

IF NO: Q.13b: Do you want your own house?

 

Q.13a: Have you already got a fur coat for your wife?

IF NO: Q.13b: Do you want a fur coat for wife?

 

Q.13a: Do you already go abroad for holidays?

IF NO: Q.13b: Would you like foreign holiday travel?

 

Q.13a: Do you have a spare bedroom for visitors?

IF NO: Q.13b: Would you like a spare bedroom for visitors?

 

Q.13a: Do you already use first class travel?

IF NO: Q.13b: Would you like to travel first class?

 

Q.13a: Do you use private education for your children?

IF NO: Q.13b: Would you like private education for your children?

 

 

 

 

 

===================== 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
===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: DO REPEAT not allowed inside DO IF

hillel vardi
In reply to this post by John F Hall

Shalom

You can restructure your data by the question to long format there after you will need only one set of do if

Hillel Vardi


On 10/01/2021 06:57, Joihn F Hall wrote:

Problem solved by Mario Giesel

Just what was needed.  Thanks Mario.

 

Some initial problems with Word document sent to Nabble.  Converted to pdf and resent to Mario, Rich, Jon and Gene

Full details on Nabble

http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?new_topic

 

Final macro syntax:

 

 

* Encoding: UTF-8.

* -----------------------------.

* Encoding: UTF-8.

DEFINE !format (!POS !CMDEND)

PRESERVE.

SET PRINTBACK = ON MPRINT = ON.

!DO !v  !IN (!1) /* Loop over format arguments*/

 

!LET !XX1 = !CONCAT(!v,"1")

!LET !XX1a = !CONCAT(!v,"1a")

!LET !XX1b = !CONCAT(!v,"1b")

!LET !XX1c = !CONCAT(!v,"1c")

!LET !XX = !v

 

!IF (!v = 'tv') !THEN !LET !wantXX = wanttv !IFEND

!IF (!v = 'phone') !THEN !LET !wantXX = wantphn !IFEND

!IF (!v = 'car') !THEN !LET !wantXX = wantcar !IFEND

!IF (!v = 'fridge') !THEN !LET !wantXX = wantfrg !IFEND

!IF (!v = 'washmach') !THEN !LET !wantXX = wantwash !IFEND

!IF (!v = 'recordpl') !THEN !LET !wantXX = wantrpl !IFEND

!IF (!v = 'cheating') !THEN !LET !wantXX = wantch !IFEND

 

count !XX1a = !XX (2) !wantXX (1)

/!XX1b = !XX (2) !wantXX (2)

/!XX1c = !XX (2) !wantXX (3).

frequencies !XX1a !XX1b !XX1c.

compute !XX1=!XX.

do if

    !XX1a=2.

compute !XX1 =2.

else if

   !XX1b=2.

compute !XX1 =3.

else if

   !XX1c=2.

compute !XX1 =4.

end if.

formats !XX1a to !XX1 (n1).

variable labels !XX1 !QUOTE(!CONCAT('Have/want ', !XX)).

value labels !XX1

1 'Yes, already have' 2 'No, but want' 3 "No, but don't want" 4 "No but don't know if want".

 

!DOEND

RESTORE.

!ENDDEFINE.

 

freq tv1 phone1 car1 fridge1 washmach1 recordpl1 cheating1.

 

 

tv1 Have/want tv

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1 Yes, already have

1185

83.7

83.9

83.9

2 No, but want

65

4.6

4.6

88.5

3 No, but don't want

161

11.4

11.4

99.9

4 No but don't know if want

2

.1

.1

100.0

Total

1413

99.9

100.0

 

Missing

System

2

.1

 

 

Total

1415

100.0

 

 

 

phone1 Have/want phone

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1 Yes, already have

322

22.8

22.8

22.8

2 No, but want

242

17.1

17.1

39.9

3 No, but don't want

827

58.4

58.5

98.4

4 No but don't know if want

23

1.6

1.6

100.0

Total

1414

99.9

100.0

 

Missing

System

1

.1

 

 

Total

1415

100.0

 

 

 

car1 Have/want car

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1 Yes, already have

540

38.2

38.2

38.2

2 No, but want

383

27.1

27.1

65.4

3 No, but don't want

477

33.7

33.8

99.2

4 No but don't know if want

12

.8

.8

100.0

Total

1412

99.8

100.0

 

Missing

System

3

.2

 

 

Total

1415

100.0

 

 

 

fridge1 Have/want fridge

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1 Yes, already have

495

35.0

35.0

35.0

2 No, but want

504

35.6

35.7

70.7

3 No, but don't want

397

28.1

28.1

98.8

4 No but don't know if want

17

1.2

1.2

100.0

Total

1413

99.9

100.0

 

Missing

System

2

.1

 

 

Total

1415

100.0

 

 

 

 

washmach1 Have/want washmach

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1 Yes, already have

702

49.6

49.6

49.6

2 No, but want

258

18.2

18.2

67.9

3 No, but don't want

441

31.2

31.2

99.1

4 No but don't know if want

13

.9

.9

100.0

Total

1414

99.9

100.0

 

Missing

System

1

.1

 

 

Total

1415

100.0

 

 

 

recordpl1 Have/want recordpl

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1.00 Yes, already have

512

36.2

36.2

36.2

2.00 No, but want

150

10.6

10.6

46.8

3.00 No, but don't want

733

51.8

51.8

98.7

4.00 No but don't know if want

19

1.3

1.3

100.0

Total

1414

99.9

100.0

 

Missing

System

1

.1

 

 

Total

1415

100.0

 

 

 

 

cheating1 Have/want cheating

 

Frequency

Percent

Valid Percent

Cumulative Percent

Valid

1 Yes, already have

83

5.9

5.9

5.9

2 No, but want

525

37.1

37.2

43.0

3 No, but don't want

774

54.7

54.8

97.8

4 No but don't know if want

31

2.2

2.2

100.0

Total

1413

99.9

100.0

 

Missing

System

2

.1

 

 

Total

1415

100.0

 

 

 

Will now apply to Runciman's second list of items only the better off can afford:

 

(These are as in the UKDS documentation: http://doc.ukdataservice.ac.uk/doc/28/mrdoc/pdf/sn28userguide.pdf, pp17-18)

(For exact wording of questions, see the facsimile questionnaire in the actual book)

 

Q.13a: Have you already got a house of your own?

IF NO: Q.13b: Do you want your own house?

 

Q.13a: Have you already got a fur coat for your wife?

IF NO: Q.13b: Do you want a fur coat for wife?

 

Q.13a: Do you already go abroad for holidays?

IF NO: Q.13b: Would you like foreign holiday travel?

 

Q.13a: Do you have a spare bedroom for visitors?

IF NO: Q.13b: Would you like a spare bedroom for visitors?

 

Q.13a: Do you already use first class travel?

IF NO: Q.13b: Would you like to travel first class?

 

Q.13a: Do you use private education for your children?

IF NO: Q.13b: Would you like private education for your children?

 

 

 

 

 

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