Stephan Lindner
2009-Jan-22 18:48 UTC
[R] Converting ddf/dct/sas data definition file to R
Dear all, I was wondering whether anyone knows about a program which converts (part of) a data definition file (such as a .dct file for stata, or .sas file for sas) into an R-script. Here is an example with a .sas file: <-- snipp VALUE HTYPE (default=32) 0 = "Not in household" 1 = "Married couple family household" 2 = "Male householder family" 3 = "Female householder family" 4 = "Male householder nonfamily" 5 = "Female householder nonfamily" 6 = "Group quarters" ; snapp --> This entry defines the variable HTYPE as a factor and assigns levels and labels. Ideally, it would be transformed into the following entry in R: data.frame$HTYPE <- factor(data.frame$HTYPE, levels=c(0,1,2,3,4,5,6), labels=c("Not in household", "Married couple family household", "Male householder family", "Female householder family", "Male householder nonfamily", "Female householder nonfamily", "Group quarters" ) ) Of course, this can be done by hand and isn't too bad with a good text editor. The reason why I am looking for a program is because I have a bunch of datasets (about 100) and there are about 200 variables defined per dataset. My goal is to provide R-scripts for these datasets such that the data files can be read in with R, making them accessible for R users. Thanks! Stephan -- ----------------------- Stephan Lindner University of Michigan
Frank E Harrell Jr
2009-Jan-22 19:01 UTC
[R] Converting ddf/dct/sas data definition file to R
The sas.get function in the Hmisc package, or the sasxport.get function, will do what you want by a different approach. Frank Stephan Lindner wrote:> Dear all, > > I was wondering whether anyone knows about a program which converts > (part of) a data definition file (such as a .dct file for stata, or > .sas file for sas) into an R-script. > > Here is an example with a .sas file: > > <-- snipp > > VALUE HTYPE (default=32) > 0 = "Not in household" > 1 = "Married couple family household" > 2 = "Male householder family" > 3 = "Female householder family" > 4 = "Male householder nonfamily" > 5 = "Female householder nonfamily" > 6 = "Group quarters" > ; > > snapp --> > > > This entry defines the variable HTYPE as a factor and assigns levels > and labels. Ideally, it would be transformed into the following entry > in R: > > > data.frame$HTYPE <- factor(data.frame$HTYPE, > levels=c(0,1,2,3,4,5,6), > labels=c("Not in household", > "Married couple family household", > "Male householder family", > "Female householder family", > "Male householder nonfamily", > "Female householder nonfamily", > "Group quarters" > ) > ) > > > Of course, this can be done by hand and isn't too bad with a good text > editor. The reason why I am looking for a program is because I have a > bunch of datasets (about 100) and there are about 200 variables defined > per dataset. My goal is to provide R-scripts for these datasets such > that the data files can be read in with R, making them accessible for > R users. > > > > Thanks! > > > Stephan > > > > > >-- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University
Stephan Kolassa
2009-Jan-22 19:08 UTC
[R] Converting ddf/dct/sas data definition file to R
Hi Stephan, Does the foreign package help? HTH, (another) Stephan Stephan Lindner schrieb:> Dear all, > > I was wondering whether anyone knows about a program which converts > (part of) a data definition file (such as a .dct file for stata, or > .sas file for sas) into an R-script. > > Here is an example with a .sas file: > > <-- snipp > > VALUE HTYPE (default=32) > 0 = "Not in household" > 1 = "Married couple family household" > 2 = "Male householder family" > 3 = "Female householder family" > 4 = "Male householder nonfamily" > 5 = "Female householder nonfamily" > 6 = "Group quarters" > ; > > snapp --> > > > This entry defines the variable HTYPE as a factor and assigns levels > and labels. Ideally, it would be transformed into the following entry > in R: > > > data.frame$HTYPE <- factor(data.frame$HTYPE, > levels=c(0,1,2,3,4,5,6), > labels=c("Not in household", > "Married couple family household", > "Male householder family", > "Female householder family", > "Male householder nonfamily", > "Female householder nonfamily", > "Group quarters" > ) > ) > > > Of course, this can be done by hand and isn't too bad with a good text > editor. The reason why I am looking for a program is because I have a > bunch of datasets (about 100) and there are about 200 variables defined > per dataset. My goal is to provide R-scripts for these datasets such > that the data files can be read in with R, making them accessible for > R users. > > > > Thanks! > > > Stephan > > > > > >