[R] how to import from SPSS without shortening variable names

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Tue Aug 19 16:56:09 CEST 2008


Timo Stolz wrote:
> Hello,
>
> as I import '.sav' files from SPSS, the variable names are shortened to
> 8 uppercase characters:
>
> "sex_of_therapist" will become "SEX_OF_TH"
>
> Is there a way around this? How can I retrieve the full names?
>
>   
Well as long as it didn't become sex_of_the_rapist...

This is actually changed in the most recent version of the foreign
package, which is contained in R 2.7.2RC:

> X <- read.spss("~/Desktop/Biobank_SPSS.sav", to.data.frame=TRUE)
Warning message:
In read.spss("~/Desktop/Biobank_SPSS.sav", to.data.frame = TRUE) :
  ~/Desktop/Biobank_SPSS.sav: File-indicated character representation
code (1252) looks like a Windows codepage
> names(X)
 [1] "Pt_id"       "Popul"       "Age"         "Sex"         "SKScode"
 [6] "Sys1"        "Sys2"        "Sys_pro"     "Dia1"        "Dia2"
[11] "Dia_pro"     "MAP1"        "MAP2"        "MAP_pro"     "MAP_p"
[16] "MAP_30_55"   "Anaesthesia" "Efedrin"     "Efedrin1"    "Efedrin2"
[21] "Metaoxedrin" "Nr"          "ACE1"        "ACE2"        "ACE_ID"
[26] "ACE3"        "ACE4"        "ADRA1A"      "ADRA2A"      "ADRB1_1"
[31] "ADRB1_2"     "ADRB2_1"     "ADRB2_2"     "ADRB2_3"     "ADRB2_4"
[36] "AGT_1"       "AGT_2"       "AGTR1"       "GNB3"        "AGTR2"
[41] "GNAS"        "NOS3_1"      "NOS3_2"      "NOS3_3"      "ADRB2_5"
[46] "ADRB2HA"     "ADRB2HB"     "ADRB2HP"     "ADRB1HA"     "ADRB1HB"
[51] "ADRB1HP"     "AGTHA"       "AGTHB"       "AGTHP"       "ACEHA"
[56] "ACEHB"       "ACEHP"       "Højde"       "Vægt"        "BMI"
[61] "BMIgroupA"   "BMIgroupB"   "BMIgroupC"

So try the prerelease or wait till Monday (and miss the opportunity to
have any bugs you find fixed before release).

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



More information about the R-help mailing list