ajdamico / sascii Goto Github PK
View Code? Open in Web Editor NEWImport ASCII files directly into R using only a SAS input script
Import ASCII files directly into R using only a SAS input script
Hi, I have a question about one of your examples in the documentation for read.SAScii
.
Here's the verbatim example:
NHIS.11.samadult.SAS.read.in.instructions <-
"ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Program_Code/NHIS/2011/SAMADULT.sas"
NHIS.11.samadult.file.location <-
"ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/NHIS/2011/samadult.zip"store the NHIS file as an R data frame!
NHIS.11.samadult.df <-
read.SAScii (
NHIS.11.samadult.file.location ,
NHIS.11.samadult.SAS.read.in.instructions ,
zipped = T, )or store the NHIS SAS import instructions for use in a
read.fwf function call outside of the read.SAScii function
NHIS.11.samadult.sas <- parse.SAScii( NHIS.11.samadult.SAS.read.in.instructions )
save the data frame now for instantaneous loading later
save( NHIS.11.samadult.df , file = "NHIS.11.samadult.data.rda" )
I am trying to do the same with the 2010 version of the survey. However, with both this 2011 file and the 2010 file I get the error Error in toupper(SASinput) : invalid multibyte string 533
with the read.SAScii
call. What can you make of it? Thanks!
R 3.0.0 and beyond requires packages to include NAMESPACE files. See discussion here:
https://stackoverflow.com/questions/17196225/error-a-namespace-file-is-required
Using the following code, I get the following error.
Any updates on code for previous versions?
Thanks
{install.packages("SAScii", dependencies = TRUE) }
Warning in install.packages :
package ‘SAScii’ is not available for this version of R
Hi Anthony.
I was wondering if there would be a way to improve the speed of SAScii by using read_fwf()
from package readr
or using laf_open_fwf()
from package LaF
instead of read.fwf
. There is an interesting discussion about a these packages in this SO thread.
ps. Thank you for developing SAScii. This is a great package and I'm sure many users in the R community are grateful for it!
Hello, I've got a data file from https://www.cdc.gov/nchs/nhis/nhis_2014_data_release.htm, "ASCII data zip icon[ZIP – 1.1 MB]".
Hi, your package has been a lifesaver and significantly streamlined my code. However, I encountered the following error when running the read.SAScii()
function: Error in toupper(SASinput) : invalid multibyte string 1234.
Looking through the source code, I narrowed the error down to the toupper()
function call on line 10 and/or line 27 of the parse.SAScii()
helper function. I figure it must have something to do with the text encoding in the SAS import instructions I was supplied with, which toupper()
fails to handle.
I found a fix though, and that was to change toupper()
from base R to stri_trans_toupper()
from the stringi package. Whatever the issue was with toupper()
, stri_trans_toupper()
overcame the issue.
I am running:
R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics"
Platform: x86_64-apple-darwin17.0 (64-bit)
Code:
# Load package
library(SAScii)
# File/instruction locations
instructions_2008 <- 'ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Program_Code/NHIS/2008/SAMADULT.sas'
file_location_2008 <- 'ftp://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/NHIS/2008/samadult.zip'
# Import data
data_2008 <- read.SAScii(fn = file_location_2008,
+ sas_ri = instructions_2008,
+ zipped = TRUE)
Error in toupper(SASinput) : invalid multibyte string 1234
Hi Damico.
Here is a combination of parse.SAScii
and read_fwf{readr}
to read PNAD data using a ASCII fixed column width file.
The syntax is really simple and it is quite powerful in terms of speed.
The encoding of a SAS input file may be different from the file system encoding. Thus, trying parse.SAScii() in a system (e.g. Linux and, I guess, Mac OS X) with UTF-8 for file encoding will fail with an input file encoded in e.g. ISO-8859-1. This could be remedied by adding a "encoding" parameter in parse.SAScii() (and maybe in read.SAScii() as well), and passing this parameter to the readLines() call.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.