How to have variable name casing in Syntax match that in Data View?

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

How to have variable name casing in Syntax match that in Data View?

Art Kendall
obviously the software works the same no matter how the syntax test is cases.
However, some people think the readability of syntax is helpful for other
people.

Has anybody worked out the python or other means to edit a snippet of syntax
so that a variable always has the same spelling?
For example, if the Data View has variables Age, DateOfBirth, and MyVariable
then
all instance of the variable name would be edited to the same casing
age, AGE, aGE would all become Age
dateofbirth, DATEofBIrth, DateOfBirth would all become DateOfBirth
myVariable, MYVARIABLE, myvariable would all become MyVariable



-----
Art Kendall
Social Research Consultants
--
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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: How to have variable name casing in Syntax match that in Data View?

Art Kendall
"test is cases"  should have been "text is cased".



-----
Art Kendall
Social Research Consultants
--
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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: How to have variable name casing in Syntax match that in Data View?

Jon Peck
In reply to this post by Art Kendall
I am not aware of a tool for this, since Statistics variable names are not case sensitive.  It would be a challenge to try to parse the syntax and identify all the variable names - and then decide how to case them, but if you could input a list of names cased the way  you want them, it would be pretty easy to provide code that would make them match as long as you don't have names that match command, subcommand, or keyword names.  (Even there, it could get that mostly right).  It would be a little standalone Python code that takes as input the file you want to process and, say, another file that lists the variable names.

On Thu, Jul 30, 2020 at 2:35 PM Art Kendall <[hidden email]> wrote:
obviously the software works the same no matter how the syntax test is cases.
However, some people think the readability of syntax is helpful for other
people.

Has anybody worked out the python or other means to edit a snippet of syntax
so that a variable always has the same spelling?
For example, if the Data View has variables Age, DateOfBirth, and MyVariable
then
all instance of the variable name would be edited to the same casing
age, AGE, aGE would all become Age
dateofbirth, DATEofBIrth, DateOfBirth would all become DateOfBirth
myVariable, MYVARIABLE, myvariable would all become MyVariable



-----
Art Kendall
Social Research Consultants
--
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


--
Jon K Peck
[hidden email]

===================== 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: How to have variable name casing in Syntax match that in Data View?

Art Kendall
Yes consistency in the/ casing/ for procedures, operators, options, etc would
probably be a bear.  But the new /coloring /in a syntax window does mostly
distinguish those things.

If I follow your suggestion.
1 make sure the casing is as desired in the data view.
2 Extract the variable names from the data view to text in another dataset.
Maybe in a syntax window or a data window. Much like the SPSSINC MODIFY you
posted in the last few days.
3 then use some python code to look for the variable names in the syntax
file.
4 replace the text in the syntax files that has any casing with the
identical text but properly cased from the small file.

Since the alpha characters are the same no matter what the casing. I can
paste both the small dataset and the syntax into WordPerfect, use a macro,
and then paste the edited syntax into SPSS.

The whole task  is like <edit> <replace> in a loop.




-----
Art Kendall
Social Research Consultants
--
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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: How to have variable name casing in Syntax match that in Data View?

Art Kendall
In reply to this post by Jon Peck
Thanks for all your help.

Yes, consistency in the/ casing/ for procedures, operators, options, etc
would probably be a bear.  But the new /coloring /in a syntax window does
mostly distinguish those things.

If I follow your suggestion rather than directly using the fileinfo directly
one could
1 make sure the casing is as desired in the data view.
2 Extract the variable names from the data view to text in another dataset.
(Maybe in a syntax window or a data window. Much like the SPSSINC MODIFY you
posted in the last few days.)
3 then use some python code to look in the syntax file for each variable
name in the smaller file.
4 replace the text in the syntax files that has any casing with the
identical text but properly cased from the small file.

Since the alpha characters are the same no matter what the casing. I can
paste both the small dataset and the syntax into WordPerfect, use a macro,
and then paste the edited syntax into SPSS.



-----
Art Kendall
Social Research Consultants
--
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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: How to have variable name casing in Syntax match that in Data View?

Jon Peck
In reply to this post by Art Kendall
It would be easy to just pick up the variables from the DE and apply that to a syntax file.  That , however, would miss inconsistencies in variables created by the  syntax via transformation code or procedure output.  If you ran all the code first, the variables would then exist at the end in most cases, but there could still be intermediate inconsistencies. 

On Thu, Jul 30, 2020 at 3:33 PM Art Kendall <[hidden email]> wrote:
Yes consistency in the/ casing/ for procedures, operators, options, etc would
probably be a bear.  But the new /coloring /in a syntax window does mostly
distinguish those things.

If I follow your suggestion.
1 make sure the casing is as desired in the data view.
2 Extract the variable names from the data view to text in another dataset.
Maybe in a syntax window or a data window. Much like the SPSSINC MODIFY you
posted in the last few days.
3 then use some python code to look for the variable names in the syntax
file.
4 replace the text in the syntax files that has any casing with the
identical text but properly cased from the small file.

Since the alpha characters are the same no matter what the casing. I can
paste both the small dataset and the syntax into WordPerfect, use a macro,
and then paste the edited syntax into SPSS.

The whole task  is like <edit> <replace> in a loop.




-----
Art Kendall
Social Research Consultants
--
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
--
Jon K Peck
[hidden email]

===================== 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: How to have variable name casing in Syntax match that in Data View?

Bruce Weaver
Administrator
In reply to this post by Art Kendall
Art, you weren't an AWK user back in the day by any chance, were you?  I was
not, but I had a colleague who did use it quite a lot, and I'm sure he could
have done something like this without too much difficulty.  I imagine the
approach would be pretty similar to what Jon described regarding use of
Python.  

https://en.wikipedia.org/wiki/AWK

This won't help with fixing syntax after the fact, but if one always pastes
variables into the syntax file, they will have the same case as shown in the
Data Editor panels.  When you are writing the command yourself (rather than
generating it via the GUI) and just want to paste the variables, you can use
the dialog that comes up under Utilities > Variables.  

HTH.



Art Kendall wrote

> obviously the software works the same no matter how the syntax test is
> cases.
> However, some people think the readability of syntax is helpful for other
> people.
>
> Has anybody worked out the python or other means to edit a snippet of
> syntax
> so that a variable always has the same spelling?
> For example, if the Data View has variables Age, DateOfBirth, and
> MyVariable
> then
> all instance of the variable name would be edited to the same casing
> age, AGE, aGE would all become Age
> dateofbirth, DATEofBIrth, DateOfBirth would all become DateOfBirth
> myVariable, MYVARIABLE, myvariable would all become MyVariable
>
>
>
> -----
> Art Kendall
> Social Research Consultants
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: How to have variable name casing in Syntax match that in Data View?

Jon Peck
I wrote masses of awk code pre Python, but its very rigid structure was a nuisance, and there were no debugging tools.  Using Python instead was a great step forward.

On Thu, Jul 30, 2020 at 3:48 PM Bruce Weaver <[hidden email]> wrote:
Art, you weren't an AWK user back in the day by any chance, were you?  I was
not, but I had a colleague who did use it quite a lot, and I'm sure he could
have done something like this without too much difficulty.  I imagine the
approach would be pretty similar to what Jon described regarding use of
Python. 

https://en.wikipedia.org/wiki/AWK

This won't help with fixing syntax after the fact, but if one always pastes
variables into the syntax file, they will have the same case as shown in the
Data Editor panels.  When you are writing the command yourself (rather than
generating it via the GUI) and just want to paste the variables, you can use
the dialog that comes up under Utilities > Variables. 

HTH.



Art Kendall wrote
> obviously the software works the same no matter how the syntax test is
> cases.
> However, some people think the readability of syntax is helpful for other
> people.
>
> Has anybody worked out the python or other means to edit a snippet of
> syntax
> so that a variable always has the same spelling?
> For example, if the Data View has variables Age, DateOfBirth, and
> MyVariable
> then
> all instance of the variable name would be edited to the same casing
> age, AGE, aGE would all become Age
> dateofbirth, DATEofBIrth, DateOfBirth would all become DateOfBirth
> myVariable, MYVARIABLE, myvariable would all become MyVariable
>
>
>
> -----
> Art Kendall
> Social Research Consultants
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

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





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
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
--
Jon K Peck
[hidden email]

===================== 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: How to have variable name casing in Syntax match that in Data View?

Art Kendall
In reply to this post by Jon Peck
Thanks.

I never used AWK.  I have used lots of tools over the years.

My syntax is a mix of typed and pasted from the GUI.  Making the syntax a
little cleaner periodically as it is being developed would help. I go back
and redraft until the syntax does what I intend. (Although, SPSS insists on
doing want I say.)  I go back vertically aligning, auto-indenting,
clarifying comments, etc.

The cleaning up the syntax would be helpful before handing the syntax off to
others.



-----
Art Kendall
Social Research Consultants
--
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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: How to have variable name casing in Syntax match that in Data View?

Art Kendall
this kludge works. It does give notice if strings in the first columns are
never found.
go to
https://wptoolbox.com/library/Replacem.html
download the macro and unzip it and place according to the embedded
instructions.

-- open the variables views
-- edit the Names to the case you want
-- highlight and copy "Name" column
-- paste it into a WordPerfect document Replacem.wpd
-- change it to a table
-- put the same info in 2 columns (This works because the default replace is
case-insensitive for the find field.)
-- <save> that according to the embedded instructions.
-- open the syntax window and <select all>
-- copy it into a WordPerfect document.
-- play the macro
-- <select all> <copy> then <paste> into an SPSS syntax window.

The macro can handle up to 9 lists of things to replace.

I do not know if it is worth the effort to develop a WordPerfect procedure
for other things since WP is no longer as widely used and syntax coloring
goes a long way to distinguish procedures, options, etc. The options Tab has
Bold, Italics, Underline, and Color.

Another thing that would only need to worked out once for an individual's
style.
 a two column file with symbolic operators in one column and text operators
in the other
>     GT
>=  GE
However, the concept of distinguishing "=" as a logical operator vs an
assignment operator could not be handled this way.


I do not know if it is worth the effort to develop a WordPerfect procedure
for casing other things since WP is no longer as widely used and syntax
coloring goes a long way to distinguish procedures, options, etc. For
Commands, SubCommands, KeyWords, etc. the options Tab has Bold, Italics,
Underline, and Color.




-----
Art Kendall
Social Research Consultants
--
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
Art Kendall
Social Research Consultants