Find all variables with no variable label

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

Find all variables with no variable label

emma78
Hi,
may be you can help me with this little problem.
I use this python to find all variables with a specific pattern in their variable labels.
It is working, but now I have to search for all var which have no text in the label, what do I have to write here
targetPattern =  'TEXT' #Specify target pattern.? If I leave it blank, all variables are found.

Thank you!


begin program.
targetPattern =  'TEXT' #Specify target pattern.
import spss
varList = [spss.GetVariableName(v) for v in range(spss.GetVariableCount()) if targetPattern in spss.GetVariableLabel(v)]
print varList
spss.SetMacroValue("!thevars2", "\n".join(varList))
end program.
Reply | Threaded
Open this post in threaded view
|

Re: Find all variables with no variable label

John F Hall
Emma

Not sure if will work on blank labels, but one trick I discovered is
to highlight the column by clicking on the header, then use CTRL+F and
CTRL+H to search for/replace text strings.  It works on Labels and on
Values and you can always use CTRL+Z if it doesn't.


John F Hall (Mr)
[Retired academic survey researcher]

Email:   [hidden email]  
Website: www.surveyresearch.weebly.com
SPSS start page:
www.surveyresearch.weebly.com/1-survey-analysis-workshop



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf
Of emma78
Sent: 16 February 2017 11:34
To: [hidden email]
Subject: Find all variables with no variable label

Hi,
may be you can help me with this little problem.
I use this python to find all variables with a specific pattern in
their variable labels.
It is working, but now I have to search for all var which have no text
in the label, what do I have to write here targetPattern =  'TEXT'
#Specify target pattern.? If I leave it blank, all variables are
found.

Thank you!


begin program.
targetPattern =  'TEXT' #Specify target pattern.
import spss
varList = [spss.GetVariableName(v) for v in
range(spss.GetVariableCount()) if targetPattern in
spss.GetVariableLabel(v)] print varList
spss.SetMacroValue("!thevars2", "\n".join(varList)) end program.



--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Find-all-variables-with-
no-variable-label-tp5733828.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

=====================
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: Find all variables with no variable label

emma78
Thank you, but I need all variables with no variable label saved in a macro, so that I can use them afterwards automatically in a syntax.
Reply | Threaded
Open this post in threaded view
|

Re: Find all variables with no variable label

Andy W
In reply to this post by emma78
You can change the test to the length of the variable label, which when empty is zero.

DATA LIST FREE / A B C.
BEGIN DATA
1 2 3
END DATA.
DATASET NAME Sim.
VARIABLE LABELS B 'Test'.
EXECUTE.

begin program.
import spss
varList = [spss.GetVariableName(v) for v in range(spss.GetVariableCount()) if len(spss.GetVariableLabel(v)) == 0]
print varList
spss.SetMacroValue("!thevars2", "\n".join(varList))
end program.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: Find all variables with no variable label

Art Kendall
I have long suggested that SPSS have options that help users enhance readability and quality.

A. that the data view is filled in before doing any analysis

I would like to see (at first as an addon) checking and warning before allowing procedures to use variables
-- whether there are unlabelled variables
-- if there are fewer than, say, 10 values for a variable and value labels are missing
-- if there are user missing values that don't have value labels
-- if there are unnecessary decimal places in display formats, e.g, likert items that are not f1 or f2.

B. Assure that that all sysmis values have been converted to user missing values.

C. Assure that sysmis is never assigned by user commands.

D. Warn when loops etc are not indented

E. warn when continuations lines of procedures are not indented.

F. warn of inconsistency in casing of PROCEDURES, Options, Functions.

G. option to convert symbolic operators to conventional operators, especially to distinguish EQ fro the assignment operator "="

H. Check syntax for variations in casing of variables. Then ask which is preferred and updating all the occurrences to the same casing.
--------
ALSO
apply all these kinds of checks to all example system files and documentation to that they model good practices.



Art Kendall
Social Research Consultants