Syntax improvement

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

Syntax improvement

mils
Hi everyone,

I have the following syntax and I was wondering if there is a way (probably by using "repeat")  to make the syntax shorter?!

Thanks for your help!!!!



fre  Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last
Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last
Q9aSegmentQus13Ibelievethatcontinualeducationandc_last
Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last
Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last
Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last
Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last
Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last
Q9cSegmentQus810Ikeepuptodateonscientificadvance_last
Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last .

compute Q9_1=$sysmis.
compute Q9_2=$sysmis.
compute Q9_3=$sysmis.
compute Q9_4=$sysmis.
compute Q9_5=$sysmis.
compute Q9_6=$sysmis.
compute Q9_7=$sysmis.
compute Q9_8=$sysmis.
compute Q9_9=$sysmis.
compute Q9_10=$sysmis.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="1 - Do not agree at all") q9_1=1.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="2") q9_1=2.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="3") q9_1=3.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="4") q9_1=4.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="5") q9_1=5.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="6") q9_1=6.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="7 - Agree completely") q9_1=7.

if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="1 - Do not agree at all") q9_2=1.
if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="2") q9_2=2.
if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="3") q9_2=3.
if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="4") q9_2=4.
if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="5") q9_2=5.
if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="6") q9_2=6.
if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="7 - Agree completely") q9_2=7.

if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="1 - Do not agree at all") q9_3=1.
if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="2") q9_3=2.
if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="3") q9_3=3.
if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="4") q9_3=4.
if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="5") q9_3=5.
if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="6") q9_3=6.
if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="7 - Agree completely") q9_3=7.

if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="1 - Do not agree at all") q9_4=1.
if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="2") q9_4=2.
if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="3") q9_4=3.
if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="4") q9_4=4.
if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="5") q9_4=5.
if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="6") q9_4=6.
if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="7 - Agree completely") q9_4=7.

if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="1 - Do not agree at all") q9_5=1.
if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="2") q9_5=2.
if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="3") q9_5=3.
if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="4") q9_5=4.
if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="5") q9_5=5.
if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="6") q9_5=6.
if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="7 - Agree completely") q9_5=7.

fre Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="1 - Do not agree at a") q9_6=1.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="2") q9_6=2.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="3") q9_6=3.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="4") q9_6=4.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="5") q9_6=5.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="6") q9_6=6.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="7 - Agree completely") q9_6=7.

if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="1 - Do not agree at all") q9_7=1.
if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="2") q9_7=2.
if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="3") q9_7=3.
if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="4") q9_7=4.
if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="5") q9_7=5.
if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="6") q9_7=6.
if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="7 - Agree completely") q9_7=7.

if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="1 - Do not agree at all") q9_8=1.
if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="2") q9_8=2.
if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="3") q9_8=3.
if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="4") q9_8=4.
if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="5") q9_8=5.
if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="6") q9_8=6.
if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="7 - Agree completely") q9_8=7.

if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="1 - Do not agree at all") q9_9=1.
if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="2") q9_9=2.
if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="3") q9_9=3.
if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="4") q9_9=4.
if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="5") q9_9=5.
if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="6") q9_9=6.
if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="7 - Agree completely") q9_9=7.

if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="1 - Do not agree at a") q9_10=1.
if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="2") q9_10=2.
if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="3") q9_10=3.
if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="4") q9_10=4.
if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="5") q9_10=5.
if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="6") q9_10=6.
if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="7 - Agree completely") q9_10=7.


var lab Q9_1 "Itrustmyownpersonalexperienceandi".
var lab Q9_2 "Iprefertowaituntilmoreisknownabo".
var lab Q9_3 "Ibelievethatcontinualeducationandc".
var lab Q9_4 "Highlyinformedpatientsaremorediffic".
var lab Q9_5 "Iaccommodatetreatmentnaïvepatientre".
var lab Q9_6 "Iactivelyseeknewapproachesanddevel".
var lab Q9_7 "IoftendiscussdevelopmentsinHBVwith".
var lab Q9_8 "0Ihighlyvalueinformationprovidedby".
var lab Q9_9 "0Ikeepuptodateonscientificadvance".
var lab Q9_10 "0Mychoiceoftherapyisstronglyinflue".

val lab q9_1 q9_2 q9_3 q9_4 q9_5 q9_6 q9_7 q9_8 q9_9 q9_10
1 '1 - Do not agree at all'
2 '2'
3 '3'
4 '4'
5 '5'
6 '6'
7 '7 - Agree completely'.
fre q9_1 q9_2 q9_3 q9_4 q9_5 q9_6 q9_7 q9_8 q9_9 q9_10
mils
Reply | Threaded
Open this post in threaded view
|

Re: Syntax improvement

Andy W
Yep you have the right idea with do repeat, something like this (untested below) will work. NOTE: I don't bother to write all of your really long variable names on the "eval" list - assuming they aren't contiguous in your dataset you can't use the "TO" modifier and will just have to list them out each seperately.

********************************************************************.
*This will initialize 10 variables - will be system missing.
vector q9_(10).
*NOTE: TO ONLY WORKS IF THE VARIABLES ARE CONTIGUOUS IN THE DATA MATRIX - PROB NOT THE CASE IN YOUR EXAMPLE.
*JUST REPLACE TO WITH EVERY INDIVIDUAL VARIABLE NAME.
do repeat q9 = q9_1 to q9_10
/eval = Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last to Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last.
if (eval="1 - Do not agree at a") q9=1.
if (eval="2") q9_10=2.
if (eval="3") q9_10=3.
if (eval="4") q9_10=4.
if (eval="5") q9_10=5.
if (eval="6") q9_10=6.
if (eval="7 - Agree completely") q9_10=7.
end repeat.
var lab Q9_1 "Itrustmyownpersonalexperienceandi".
var lab Q9_2 "Iprefertowaituntilmoreisknownabo".
var lab Q9_3 "Ibelievethatcontinualeducationandc".
var lab Q9_4 "Highlyinformedpatientsaremorediffic".
var lab Q9_5 "Iaccommodatetreatmentnaïvepatientre".
var lab Q9_6 "Iactivelyseeknewapproachesanddevel".
var lab Q9_7 "IoftendiscussdevelopmentsinHBVwith".
var lab Q9_8 "0Ihighlyvalueinformationprovidedby".
var lab Q9_9 "0Ikeepuptodateonscientificadvance".
var lab Q9_10 "0Mychoiceoftherapyisstronglyinflue".

val lab q9_1 to q9_10
1 '1 - Do not agree at all'
2 '2'
3 '3'
4 '4'
5 '5'
6 '6'
7 '7 - Agree completely'.
********************************************************************.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: Syntax improvement

David Marso
Administrator
I would nip the following in the bud!
if (eval="1 - Do not agree at a") q9=1.
if (eval="2") q9_10=2.
if (eval="3") q9_10=3.
if (eval="4") q9_10=4.
if (eval="5") q9_10=5.
if (eval="6") q9_10=6.
if (eval="7 - Agree completely") q9_10=7.

Simplifies to:
COMPUTE q9=NUMBER(CHAR.SUBSTR(eval,1,1),F1).
BTW:  The q9_10 references should be q9 in Andy's posting.
---
Also those LONG variable names are a PITA to read.
Just because variable names CAN be up to 64 bytes does not mean they SHOULD be ;-(
Try CamelCase for readability?
Q9aSegmentQus13ITrustMyOwnPersonalExperienceAndI_last

Andy W wrote
Yep you have the right idea with do repeat, something like this (untested below) will work. NOTE: I don't bother to write all of your really long variable names on the "eval" list - assuming they aren't contiguous in your dataset you can't use the "TO" modifier and will just have to list them out each seperately.

********************************************************************.
*This will initialize 10 variables - will be system missing.
vector q9_(10).
*NOTE: TO ONLY WORKS IF THE VARIABLES ARE CONTIGUOUS IN THE DATA MATRIX - PROB NOT THE CASE IN YOUR EXAMPLE.
*JUST REPLACE TO WITH EVERY INDIVIDUAL VARIABLE NAME.
do repeat q9 = q9_1 to q9_10
/eval = Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last to Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last.
if (eval="1 - Do not agree at a") q9=1.
if (eval="2") q9_10=2.
if (eval="3") q9_10=3.
if (eval="4") q9_10=4.
if (eval="5") q9_10=5.
if (eval="6") q9_10=6.
if (eval="7 - Agree completely") q9_10=7.
end repeat.
var lab Q9_1 "Itrustmyownpersonalexperienceandi".
var lab Q9_2 "Iprefertowaituntilmoreisknownabo".
var lab Q9_3 "Ibelievethatcontinualeducationandc".
var lab Q9_4 "Highlyinformedpatientsaremorediffic".
var lab Q9_5 "Iaccommodatetreatmentnaïvepatientre".
var lab Q9_6 "Iactivelyseeknewapproachesanddevel".
var lab Q9_7 "IoftendiscussdevelopmentsinHBVwith".
var lab Q9_8 "0Ihighlyvalueinformationprovidedby".
var lab Q9_9 "0Ikeepuptodateonscientificadvance".
var lab Q9_10 "0Mychoiceoftherapyisstronglyinflue".

val lab q9_1 to q9_10
1 '1 - Do not agree at all'
2 '2'
3 '3'
4 '4'
5 '5'
6 '6'
7 '7 - Agree completely'.
********************************************************************.
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?"
Reply | Threaded
Open this post in threaded view
|

Re: Syntax improvement

Jon K Peck
In reply to this post by Andy W
You could come pretty close with just
AUTORECODE VARIABLES = blah blah blan /INTO q9_1 to q9_10
/group.

That has the extra benefit of copying the variable labels, too.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        Andy W <[hidden email]>
To:        [hidden email],
Date:        05/31/2013 10:43 AM
Subject:        Re: [SPSSX-L] Syntax improvement
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Yep you have the right idea with do repeat, something like this (untested
below) will work. NOTE: I don't bother to write all of your really long
variable names on the "eval" list - assuming they aren't contiguous in your
dataset you can't use the "TO" modifier and will just have to list them out
each seperately.

********************************************************************.
*This will initialize 10 variables - will be system missing.
vector q9_(10).
*NOTE: TO ONLY WORKS IF THE VARIABLES ARE CONTIGUOUS IN THE DATA MATRIX -
PROB NOT THE CASE IN YOUR EXAMPLE.
*JUST REPLACE TO WITH EVERY INDIVIDUAL VARIABLE NAME.
do repeat q9 = q9_1 to q9_10
/eval = Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last to
Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last.
if (eval="1 - Do not agree at a") q9=1.
if (eval="2") q9_10=2.
if (eval="3") q9_10=3.
if (eval="4") q9_10=4.
if (eval="5") q9_10=5.
if (eval="6") q9_10=6.
if (eval="7 - Agree completely") q9_10=7.
end repeat.
var lab Q9_1 "Itrustmyownpersonalexperienceandi".
var lab Q9_2 "Iprefertowaituntilmoreisknownabo".
var lab Q9_3 "Ibelievethatcontinualeducationandc".
var lab Q9_4 "Highlyinformedpatientsaremorediffic".
var lab Q9_5 "Iaccommodatetreatmentnaïvepatientre".
var lab Q9_6 "Iactivelyseeknewapproachesanddevel".
var lab Q9_7 "IoftendiscussdevelopmentsinHBVwith".
var lab Q9_8 "0Ihighlyvalueinformationprovidedby".
var lab Q9_9 "0Ikeepuptodateonscientificadvance".
var lab Q9_10 "0Mychoiceoftherapyisstronglyinflue".

val lab q9_1 to q9_10
1 '1 - Do not agree at all'
2 '2'
3 '3'
4 '4'
5 '5'
6 '6'
7 '7 - Agree completely'.
********************************************************************.



-----
Andy W
[hidden email]
http://andrewpwheeler.wordpress.com/
--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Syntax-improvement-tp5720504p5720506.html
Sent from the SPSSX Discussion mailing list archive at 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: Syntax improvement

David Marso
Administrator
AUTORECODE is the obvious choice!

Jon K Peck wrote
You could come pretty close with just
AUTORECODE VARIABLES = blah blah blan /INTO q9_1 to q9_10
/group.

That has the extra benefit of copying the variable labels, too.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:   Andy W <[hidden email]>
To:     [hidden email],
Date:   05/31/2013 10:43 AM
Subject:        Re: [SPSSX-L] Syntax improvement
Sent by:        "SPSSX(r) Discussion" <[hidden email]>



Yep you have the right idea with do repeat, something like this (untested
below) will work. NOTE: I don't bother to write all of your really long
variable names on the "eval" list - assuming they aren't contiguous in
your
dataset you can't use the "TO" modifier and will just have to list them
out
each seperately.

********************************************************************.
*This will initialize 10 variables - will be system missing.
vector q9_(10).
*NOTE: TO ONLY WORKS IF THE VARIABLES ARE CONTIGUOUS IN THE DATA MATRIX -
PROB NOT THE CASE IN YOUR EXAMPLE.
*JUST REPLACE TO WITH EVERY INDIVIDUAL VARIABLE NAME.
do repeat q9 = q9_1 to q9_10
/eval = Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last to
Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last.
if (eval="1 - Do not agree at a") q9=1.
if (eval="2") q9_10=2.
if (eval="3") q9_10=3.
if (eval="4") q9_10=4.
if (eval="5") q9_10=5.
if (eval="6") q9_10=6.
if (eval="7 - Agree completely") q9_10=7.
end repeat.
var lab Q9_1 "Itrustmyownpersonalexperienceandi".
var lab Q9_2 "Iprefertowaituntilmoreisknownabo".
var lab Q9_3 "Ibelievethatcontinualeducationandc".
var lab Q9_4 "Highlyinformedpatientsaremorediffic".
var lab Q9_5 "Iaccommodatetreatmentnaïvepatientre".
var lab Q9_6 "Iactivelyseeknewapproachesanddevel".
var lab Q9_7 "IoftendiscussdevelopmentsinHBVwith".
var lab Q9_8 "0Ihighlyvalueinformationprovidedby".
var lab Q9_9 "0Ikeepuptodateonscientificadvance".
var lab Q9_10 "0Mychoiceoftherapyisstronglyinflue".

val lab q9_1 to q9_10
1 '1 - Do not agree at all'
2 '2'
3 '3'
4 '4'
5 '5'
6 '6'
7 '7 - Agree completely'.
********************************************************************.



-----
Andy W
[hidden email]
http://andrewpwheeler.wordpress.com/
--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Syntax-improvement-tp5720504p5720506.html

Sent from the SPSSX Discussion mailing list archive at 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
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?"
Reply | Threaded
Open this post in threaded view
|

Re: Syntax improvement

Art Kendall
In reply to this post by mils
I) replace the whole thing with AUTORECODE.

If future syntax drafting use the conventional logical operator EQ as the logical operator not the = sign which people confuse with the assignment operator.
Avoids falsely assigned sysmis values.
A good rule of thumb for QA is that syntax should be elaborated until it does not produce any sysmis values. I.E., that the syntax give no instructions that the computer is unable to follow.
Initialize to a user missing value, thee values are missing because you said they should be NOT because the computer was unable to follow your instructions.
Use variable labels and variable names.
Assign value labels that mean something about the substantive nature of the response scale items.


Art Kendall
Social Research Consultants
On 5/31/2013 11:42 AM, mils [via SPSSX Discussion] wrote:
Hi everyone,

I have the following syntax and I was wondering if there is a way (probably by using "repeat")  to make the syntax shorter?!

Thanks for your help!!!!



fre  Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last
Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last
Q9aSegmentQus13Ibelievethatcontinualeducationandc_last
Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last
Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last
Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last
Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last
Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last
Q9cSegmentQus810Ikeepuptodateonscientificadvance_last
Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last .

compute Q9_1=$sysmis.
compute Q9_2=$sysmis.
compute Q9_3=$sysmis.
compute Q9_4=$sysmis.
compute Q9_5=$sysmis.
compute Q9_6=$sysmis.
compute Q9_7=$sysmis.
compute Q9_8=$sysmis.
compute Q9_9=$sysmis.
compute Q9_10=$sysmis.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="1 - Do not agree at all") q9_1=1.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="2") q9_1=2.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="3") q9_1=3.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="4") q9_1=4.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="5") q9_1=5.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="6") q9_1=6.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="7 - Agree completely") q9_1=7.

if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="1 - Do not agree at all") q9_2=1.
if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="2") q9_2=2.
if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="3") q9_2=3.
if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="4") q9_2=4.
if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="5") q9_2=5.
if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="6") q9_2=6.
if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="7 - Agree completely") q9_2=7.

if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="1 - Do not agree at all") q9_3=1.
if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="2") q9_3=2.
if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="3") q9_3=3.
if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="4") q9_3=4.
if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="5") q9_3=5.
if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="6") q9_3=6.
if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="7 - Agree completely") q9_3=7.

if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="1 - Do not agree at all") q9_4=1.
if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="2") q9_4=2.
if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="3") q9_4=3.
if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="4") q9_4=4.
if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="5") q9_4=5.
if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="6") q9_4=6.
if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="7 - Agree completely") q9_4=7.

if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="1 - Do not agree at all") q9_5=1.
if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="2") q9_5=2.
if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="3") q9_5=3.
if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="4") q9_5=4.
if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="5") q9_5=5.
if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="6") q9_5=6.
if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="7 - Agree completely") q9_5=7.

fre Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="1 - Do not agree at a") q9_6=1.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="2") q9_6=2.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="3") q9_6=3.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="4") q9_6=4.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="5") q9_6=5.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="6") q9_6=6.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="7 - Agree completely") q9_6=7.

if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="1 - Do not agree at all") q9_7=1.
if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="2") q9_7=2.
if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="3") q9_7=3.
if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="4") q9_7=4.
if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="5") q9_7=5.
if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="6") q9_7=6.
if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="7 - Agree completely") q9_7=7.

if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="1 - Do not agree at all") q9_8=1.
if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="2") q9_8=2.
if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="3") q9_8=3.
if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="4") q9_8=4.
if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="5") q9_8=5.
if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="6") q9_8=6.
if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="7 - Agree completely") q9_8=7.

if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="1 - Do not agree at all") q9_9=1.
if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="2") q9_9=2.
if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="3") q9_9=3.
if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="4") q9_9=4.
if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="5") q9_9=5.
if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="6") q9_9=6.
if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="7 - Agree completely") q9_9=7.

if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="1 - Do not agree at a") q9_10=1.
if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="2") q9_10=2.
if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="3") q9_10=3.
if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="4") q9_10=4.
if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="5") q9_10=5.
if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="6") q9_10=6.
if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="7 - Agree completely") q9_10=7.


var lab Q9_1 "Itrustmyownpersonalexperienceandi".
var lab Q9_2 "Iprefertowaituntilmoreisknownabo".
var lab Q9_3 "Ibelievethatcontinualeducationandc".
var lab Q9_4 "Highlyinformedpatientsaremorediffic".
var lab Q9_5 "Iaccommodatetreatmentnaïvepatientre".
var lab Q9_6 "Iactivelyseeknewapproachesanddevel".
var lab Q9_7 "IoftendiscussdevelopmentsinHBVwith".
var lab Q9_8 "0Ihighlyvalueinformationprovidedby".
var lab Q9_9 "0Ikeepuptodateonscientificadvance".
var lab Q9_10 "0Mychoiceoftherapyisstronglyinflue".

val lab q9_1 q9_2 q9_3 q9_4 q9_5 q9_6 q9_7 q9_8 q9_9 q9_10
1 '1 - Do not agree at all'
2 '2'
3 '3'
4 '4'
5 '5'
6 '6'
7 '7 - Agree completely'.
fre q9_1 q9_2 q9_3 q9_4 q9_5 q9_6 q9_7 q9_8 q9_9 q9_10
mils



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Syntax-improvement-tp5720504.html
To start a new topic under SPSSX Discussion, email [hidden email]
To unsubscribe from SPSSX Discussion, click here.
NAML

Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Syntax improvement

Albert-Jan Roskam
I am a big fan of readable, meaningful, pronounceable variable names, but the variable names used here are too long and not easy to read and even more annoying to write. "Shorter names are generally better than longer ones, so long as they are clear. Add no more context to a name than is necessary." (Chapter 2, page 30)
http://www.e-reading-lib.org/bookreader.php/134601/Clean_Code_-_A_Handbook_of_Agile_Software_Craftsmanship.pdf
 
Regards,
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a
fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

From: Art Kendall <[hidden email]>
To: [hidden email]
Sent: Friday, May 31, 2013 8:07 PM
Subject: Re: [SPSSX-L] Syntax improvement

I) replace the whole thing with AUTORECODE.

If future syntax drafting use the conventional logical operator EQ as the logical operator not the = sign which people confuse with the assignment operator.
Avoids falsely assigned sysmis values.
A good rule of thumb for QA is that syntax should be elaborated until it does not produce any sysmis values. I.E., that the syntax give no instructions that the computer is unable to follow.
Initialize to a user missing value, thee values are missing because you said they should be NOT because the computer was unable to follow your instructions.
Use variable labels and variable names.
Assign value labels that mean something about the substantive nature of the response scale items.


Art Kendall
Social Research Consultants
On 5/31/2013 11:42 AM, mils [via SPSSX Discussion] wrote:
Hi everyone,

I have the following syntax and I was wondering if there is a way (probably by using "repeat")  to make the syntax shorter?!

Thanks for your help!!!!



fre  Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last
Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last
Q9aSegmentQus13Ibelievethatcontinualeducationandc_last
Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last
Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last
Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last
Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last
Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last
Q9cSegmentQus810Ikeepuptodateonscientificadvance_last
Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last .

compute Q9_1=$sysmis.
compute Q9_2=$sysmis.
compute Q9_3=$sysmis.
compute Q9_4=$sysmis.
compute Q9_5=$sysmis.
compute Q9_6=$sysmis.
compute Q9_7=$sysmis.
compute Q9_8=$sysmis.
compute Q9_9=$sysmis.
compute Q9_10=$sysmis.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="1 - Do not agree at all") q9_1=1.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="2") q9_1=2.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="3") q9_1=3.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="4") q9_1=4.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="5") q9_1=5.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="6") q9_1=6.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="7 - Agree completely") q9_1=7.

if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="1 - Do not agree at all") q9_2=1.
if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="2") q9_2=2.
if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="3") q9_2=3.
if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="4") q9_2=4.
if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="5") q9_2=5.
if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="6") q9_2=6.
if (Q9aSegmentQus13Iprefertowaituntilmoreisknownabo_last="7 - Agree completely") q9_2=7.

if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="1 - Do not agree at all") q9_3=1.
if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="2") q9_3=2.
if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="3") q9_3=3.
if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="4") q9_3=4.
if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="5") q9_3=5.
if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="6") q9_3=6.
if (Q9aSegmentQus13Ibelievethatcontinualeducationandc_last="7 - Agree completely") q9_3=7.

if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="1 - Do not agree at all") q9_4=1.
if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="2") q9_4=2.
if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="3") q9_4=3.
if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="4") q9_4=4.
if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="5") q9_4=5.
if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="6") q9_4=6.
if (Q9bSegmentQus47Highlyinformedpatientsaremorediffic_last="7 - Agree completely") q9_4=7.

if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="1 - Do not agree at all") q9_5=1.
if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="2") q9_5=2.
if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="3") q9_5=3.
if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="4") q9_5=4.
if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="5") q9_5=5.
if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="6") q9_5=6.
if (Q9bSegmentQus47IaccommodatetreatmentnaÃvepatientr_last="7 - Agree completely") q9_5=7.

fre Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="1 - Do not agree at a") q9_6=1.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="2") q9_6=2.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="3") q9_6=3.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="4") q9_6=4.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="5") q9_6=5.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="6") q9_6=6.
if (Q9bSegmentQus47Iactivelyseeknewapproachesanddevel_last="7 - Agree completely") q9_6=7.

if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="1 - Do not agree at all") q9_7=1.
if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="2") q9_7=2.
if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="3") q9_7=3.
if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="4") q9_7=4.
if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="5") q9_7=5.
if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="6") q9_7=6.
if (Q9bSegmentQus47IoftendiscussdevelopmentsinHBVwith_last="7 - Agree completely") q9_7=7.

if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="1 - Do not agree at all") q9_8=1.
if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="2") q9_8=2.
if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="3") q9_8=3.
if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="4") q9_8=4.
if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="5") q9_8=5.
if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="6") q9_8=6.
if (Q9cSegmentQus810Ihighlyvalueinformationprovidedby_last="7 - Agree completely") q9_8=7.

if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="1 - Do not agree at all") q9_9=1.
if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="2") q9_9=2.
if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="3") q9_9=3.
if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="4") q9_9=4.
if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="5") q9_9=5.
if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="6") q9_9=6.
if (Q9cSegmentQus810Ikeepuptodateonscientificadvance_last="7 - Agree completely") q9_9=7.

if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="1 - Do not agree at a") q9_10=1.
if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="2") q9_10=2.
if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="3") q9_10=3.
if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="4") q9_10=4.
if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="5") q9_10=5.
if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="6") q9_10=6.
if (Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last="7 - Agree completely") q9_10=7.


var lab Q9_1 "Itrustmyownpersonalexperienceandi".
var lab Q9_2 "Iprefertowaituntilmoreisknownabo".
var lab Q9_3 "Ibelievethatcontinualeducationandc".
var lab Q9_4 "Highlyinformedpatientsaremorediffic".
var lab Q9_5 "Iaccommodatetreatmentnaïvepatientre".
var lab Q9_6 "Iactivelyseeknewapproachesanddevel".
var lab Q9_7 "IoftendiscussdevelopmentsinHBVwith".
var lab Q9_8 "0Ihighlyvalueinformationprovidedby".
var lab Q9_9 "0Ikeepuptodateonscientificadvance".
var lab Q9_10 "0Mychoiceoftherapyisstronglyinflue".

val lab q9_1 q9_2 q9_3 q9_4 q9_5 q9_6 q9_7 q9_8 q9_9 q9_10
1 '1 - Do not agree at all'
2 '2'
3 '3'
4 '4'
5 '5'
6 '6'
7 '7 - Agree completely'.
fre q9_1 q9_2 q9_3 q9_4 q9_5 q9_6 q9_7 q9_8 q9_9 q9_10
mils



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Syntax-improvement-tp5720504.html
To start a new topic under SPSSX Discussion, email [hidden email]
To unsubscribe from SPSSX Discussion, click here.
NAML

Art Kendall
Social Research Consultants


View this message in context: Re: Syntax improvement
Sent from the SPSSX Discussion mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Syntax improvement

Richard Ristow
At 02:45 PM 5/31/2013, Albert-Jan Roskam wrote:

>I am a big fan of readable, meaningful,
>pronounceable variable names, but the variable
>names [like
>"Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last"]
>are too long and not easy to read and even more annoying to write.

Quite right. Very long names like that have
become fashionable in some programming circles,
because they're 'readable'. But, to my mind, they
distract from reading the *code*, because of the
effort it takes to read the *name*. (And it's
really hard to type a name like that accurately,
if you don't have a drop-down list to pull it from!)

SPSS has long had a best-of-both-worlds solution:
variable labels. Something like

VARIABLE LABELS
    Q9aSQus13a "I trust my own personal experience and [fill in"
    Q9aSQus13b "I prefer to wait until more is known about [fill in]"
    ...

Incidentally, a chain of IF statements is very
inefficient SPSS code. You've had a number of suggestions about the chain

if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="1 - Do not agree
at all") q9_1=1.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="2") q9_1=2.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="3") q9_1=3.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="4") q9_1=4.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="5") q9_1=5.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="6") q9_1=6.
if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="7Â - Agree
completely") q9_1=7.

all of which are good ones; but, minimally, this
would be much more readable, and much faster, as

RECODE Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last
    ("1 - Do not agree at all" =1)
    ("2"                       =2)
    ("3"                       =3)
    ("4"                       =4)
    ("5"                       =5)
    ("6"                       =6)
    ("7 - Agree completely"    =7)
    INTO q9_1.

It would be very wise to have an ELSE clause to
provide for your original variable not having one of the expected forms:

RECODE Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last
    ("1 - Do not agree at all" =1)
    ("2"                       =2)
    ("3"                       =3)
    ("4"                       =4)
    ("5"                       =5)
    ("6"                       =6)
    ("7 - Agree completely"    =7)
    (ELSE                      =9)
    INTO q9_1.

MISSING VALUES q9_1 (9).
VALUE LABELS   q9_1  9  'Miscode'.

=====================
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: Syntax improvement

Rich Ulrich
The initial problem is solved with AUTORECODE, and we have
moved to problems that are more generic.

I will toss in two comments. 

1) I see in the initial post, many times,
last="7� - Agree

where the character after 7 is a foreign character.  On my screen,
it is a question mark inside a black diamond.

What I see in this later post is
   last="7Â - Agree

where the character after 7 is a different foreign character. This
one looks like a capital A with a hat.

I don't know, but I guess, that the original was put in as "close-double-quote",
which are the curly ones, rather than  the type used everywhere else. 
I don't know whether SPSS would re-import these and treat them as
double-quotes.  But I'm sure that this is something that I watch out for
and get rid of.  Even if it works for now, there is long-term potential for
obscure error messages or weird behavior, from code that you *thought*
was going to adapt readily to a new package, etc.


2) The initial post include 10 statements that created and initialized Q_1 to Q_10. 
For brevity, that is most handily done as

NUMERIC Q_1 to Q_10.
RECODE Q_1 to Q_10(else= SYSMIS).

--
Rich Ulrich

> Date: Fri, 31 May 2013 16:18:25 -0400

> From: [hidden email]
> Subject: Re: Syntax improvement
> To: [hidden email]
>
> At 02:45 PM 5/31/2013, Albert-Jan Roskam wrote:
>
> >I am a big fan of readable, meaningful,
> >pronounceable variable names, but the variable
> >names [like
> >"Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last"]
> >are too long and not easy to read and even more annoying to write.
>
> Quite right. Very long names like that have
> become fashionable in some programming circles,
> because they're 'readable'. But, to my mind, they
> distract from reading the *code*, because of the
> effort it takes to read the *name*. (And it's
> really hard to type a name like that accurately,
> if you don't have a drop-down list to pull it from!)
>
> SPSS has long had a best-of-both-worlds solution:
> variable labels. Something like
>
> VARIABLE LABELS
> Q9aSQus13a "I trust my own personal experience and [fill in"
> Q9aSQus13b "I prefer to wait until more is known about [fill in]"
> ...
>
> Incidentally, a chain of IF statements is very
> inefficient SPSS code. You've had a number of suggestions about the chain
>
> if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="1 - Do not agree
> at all") q9_1=1.
> if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="2") q9_1=2.
> if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="3") q9_1=3.
> if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="4") q9_1=4.
> if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="5") q9_1=5.
> if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="6") q9_1=6.
> if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="7Â - Agree
> completely") q9_1=7.
>
> all of which are good ones; but, minimally, this
> would be much more readable, and much faster, as
>
[snip, rest ...]

Reply | Threaded
Open this post in threaded view
|

Re: Syntax improvement

Jon K Peck


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        Rich Ulrich <[hidden email]>
To:        [hidden email],
Date:        05/31/2013 05:43 PM
Subject:        Re: [SPSSX-L] Syntax improvement
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




The initial problem is solved with AUTORECODE, and we have
moved to problems that are more generic.

I will toss in two comments.  

1) I see in the initial post, many times,

last="7� - Agree

where the character after 7 is a foreign character.  On my screen,
it is a question mark inside a black diamond.

What I see in this later post is
  last="7Â - Agree

where the character after 7 is a different foreign character. This
one looks like a capital A with a hat.


>>>This could be text being read in the wrong encoding.  I would need details to pin this down.  Too many things have happened to this text by now to diagnose it.

Statistics would not convert quote equivalents such as curly quotes to standard ones, so if the quotes were wrong, it would have given a syntax error.

I don't know, but I guess, that the original was put in as "close-double-quote",
which are the curly ones, rather than  the type used everywhere else.  
I don't know whether SPSS would re-import these and treat them as
double-quotes.  But I'm sure that this is something that I watch out for
and get rid of.  Even if it works for now, there is long-term potential for
obscure error messages or weird behavior, from code that you *thought*
was going to adapt readily to a new package, etc.


2) The initial post include 10 statements that created and initialized Q_1 to Q_10.  
For brevity, that is most handily done as

NUMERIC Q_1 to Q_10.
RECODE Q_1 to Q_10(else= SYSMIS).


>>>NUMERIC initializes variables to SYSMIS (except scratch variables are initialized to 0), so the RECODE is redundant.

--
Rich Ulrich

> Date: Fri, 31 May 2013 16:18:25 -0400
> From: [hidden email]
> Subject: Re: Syntax improvement
> To: [hidden email]
>
> At 02:45 PM 5/31/2013, Albert-Jan Roskam wrote:
>
> >I am a big fan of readable, meaningful,
> >pronounceable variable names, but the variable
> >names [like
> >"Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last"]
> >are too long and not easy to read and even more annoying to write.
>
> Quite right. Very long names like that have
> become fashionable in some programming circles,
> because they're 'readable'. But, to my mind, they
> distract from reading the *code*, because of the
> effort it takes to read the *name*. (And it's
> really hard to type a name like that accurately,
> if you don't have a drop-down list to pull it from!)
>
> SPSS has long had a best-of-both-worlds solution:
> variable labels. Something like
>
> VARIABLE LABELS
> Q9aSQus13a "I trust my own personal experience and [fill in"
> Q9aSQus13b "I prefer to wait until more is known about [fill in]"
> ...
>
> Incidentally, a chain of IF statements is very
> inefficient SPSS code. You've had a number of suggestions about the chain
>
> if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="1 - Do not agree
> at all") q9_1=1.
> if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="2") q9_1=2.
> if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="3") q9_1=3.
> if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="4") q9_1=4.
> if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="5") q9_1=5.
> if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="6") q9_1=6.
> if (Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last="7Â - Agree
> completely") q9_1=7.
>
> all of which are good ones; but, minimally, this
> would be much more readable, and much faster, as
>
[snip, rest ...]


Reply | Threaded
Open this post in threaded view
|

Re: Syntax improvement

Richard Ristow
In reply to this post by Rich Ulrich
At 07:42 PM 5/31/2013, Rich Ulrich wrote:

>The initial problem is solved with AUTORECODE, and we have moved to
>problems that are more generic.

Sounds good. But I suggest remembering RECODE, as a much more compact
and efficient way of writing your original code, and workable even if
AUTORECODE doesn't come up with the recodings you want.

=====================
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: Syntax improvement

mils
In reply to this post by mils
Thanks all for your advices/suggestions!!!

I went for AUTORECODE!!!!

AUTORECODE Q9aSegmentQus13Itrustmyownpersonalexperienceandi_last to Q9cSegmentQus810Mychoiceoftherapyisstronglyinflue_last
/ into q9_1 to q9_10.


It worked just perfect!!!
mils