it is easy to parse through yourself.  if you don't care about the labels
and just want to import fixed-width file data, you can use the SAScii
package.  if you do, run this code to get 'em  :)


# load the stringr package to trim strings quickly
library(stringr)

# example proc format block--

# store the proc format text.. you can use ?readLines to import your file
instead
proc.format <- "proc format;
value $resstatus
'B'    = 'Jahresaufenthalter'
'C' = 'Niedergelassene'
'I' = 'Dipl./int. Funkt. und Angehörige'
;
run;"


# separate all strings by return characters
x <- strsplit( proc.format , "\n" )[[1]]

# then break the strings apart by the equals signs
y <- strsplit( x , "=" )


# throw out the lines you don't need by hand
# only the third through fifth rows contain anything of value.
z <- y[ 3:5 ]


# extract the first and second elements of the list `z`
value <- sapply( z , "[[" , 1 )
label <- sapply( z , "[[" , 2 )


# trim outside whitespace
value <- str_trim( value )
label <- str_trim( label )

# remove first and last ' character
value <- substr( value , 2 , nchar( value ) - 1 )
label <- substr( label , 2 , nchar( label ) - 1 )

# print the results to the screen
value
label





On Thu, Jan 17, 2013 at 10:39 AM, David Studer <stude...@gmail.com> wrote:

> Hello everybody,
>
> I imported an SAS data-file into R. open.sas7bdat() did not work,
> so I had to convert it to csv first. Now I would like to recode the
> value values into factors. Unfortunately I only have a SAS
> syntax file, having this form:
>
> proc format;
> value $resstatus
> 'B'    = 'Jahresaufenthalter'
> 'C' = 'Niedergelassene'
> 'I' = 'Dipl./int. Funkt. und Angehörige'
> ;
> run;
>
> Does anyone know if there is a possibility to change the numeric
> value labels into factor levels acording to the SAS syntax-file?
>
> I cannot do this manually as there are several hundred labels...
>
> Thank you!
>
>         [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to