Converting variable and value labels for numeric variables into upper case and reverse

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

Converting variable and value labels for numeric variables into upper case and reverse

Staffan Lindberg
Dear list!
 
I have a large file with numeric variables. The variable and value labels
are written randomly with upper and lower case. Is there a way of converting
all labels in lower case into upper case (for the whole file)?
 
A somewhat related question is converting all uppercase labels into lower
case but preserving the first letter in upper case? Is this possible ? I got
a solution from Simon Freidin for this question and found some related
instances in Rays pages (although restricted to words, not labels). I guess
what I am wondering is if there is some kind of general solution for both
these instances?
 
best
 
Staffan Lindberg
National Institute of Public Health
Reply | Threaded
Open this post in threaded view
|

Re: Converting variable and value labels for numeric variables into upper case and reverse

Simon Phillip Freidin
Ray, you can post this one if you like

cheers
Simon

/* ALL VARIABLE AND VALUE LABELS TO UPPER CASE, or SENTENCE CASE or
LOWER CASE */
set printback=on.
get file='1991 U.S. General Social Survey.sav'.
oms /if commands=['File Information'] subtypes=['Variable
Information']/destination format=sav outfile="varlabels.sav" viewer=no.
oms /if commands=['File Information'] subtypes=['Variable Values']/
destination format=sav outfile="valabels.sav" viewer=no.
display dictionary.
omsend.

get file="varlabels.sav"/keep=var1 label.
compute q=index(label,"'").
if q>0 label=concat(substr(label,1,q),substr(label,q)).
compute label=upcase(label). /* set to lower if want lower case or
sentence case */
compute substr(label,1,1)=upcase(substr(label,1,1)). /* comment out
if dont want first letter caps */
write outfile="replace-var-labels.sps"/"var labels " var1 " '" label
"'.".
exe.

get file="valabels.sav"/keep=var1 var2 label.
compute q=index(label,"'").
if q>0 label=concat(substr(label,1,q),substr(label,q)).
compute label=upcase(label). /* set to lower if want lower labels */
compute substr(label,1,1)=upcase(substr(label,1,1)). /* comment out
if dont want first letter caps */
write outfile="replace-value-labels.sps"/"add value labels " var1 " "
var2 " '" label "'.".
exe.

get file='1991 U.S. General Social Survey.sav'.
include file="replace-var-labels.sps".
include file="replace-value-labels.sps".
exe.


On 11/03/2007, at 10:12 PM, Staffan Lindberg wrote:

> Dear list!
>
> I have a large file with numeric variables. The variable and value
> labels
> are written randomly with upper and lower case. Is there a way of
> converting
> all labels in lower case into upper case (for the whole file)?
>
> A somewhat related question is converting all uppercase labels into
> lower
> case but preserving the first letter in upper case? Is this
> possible ? I got
> a solution from Simon Freidin for this question and found some related
> instances in Rays pages (although restricted to words, not labels).
> I guess
> what I am wondering is if there is some kind of general solution
> for both
> these instances?
>
> best
>
> Staffan Lindberg
> National Institute of Public Health