knitr::opts_chunk$set(echo = TRUE, collapse = TRUE, comment = "#>") library(datasus)
datasus provides catalog-driven interfaces to the tables published through
TABNET. The main workflow is:
datasus_catalogo();datasus_opcoes();Network examples are not evaluated when this vignette is built because the availability and response time of DATASUS are outside the package's control.
The local catalog can be searched without contacting DATASUS:
datasus_catalogo() datasus_catalogo("mortalidade") datasus_catalogo("cnes") datasus_catalogo("sinan")
The result identifies the system, dataset and public function to use. Once a dataset has been selected, inspect the current TABNET form:
options <- datasus_opcoes( sistema = "sim", conjunto = "obitos", abrangencia = "uf" ) options$linha options$coluna options$conteudo names(options$filtros)
Using the labels returned by datasus_opcoes() avoids embedding assumptions
about a form that the portal may change later.
sim() retrieves mortality data and sinasc() retrieves live-birth data.
Both accept a year, "last" for the latest available period, and geographic
or demographic filters.
deaths <- sim( conjunto = "obitos", abrangencia = "uf", periodo = 2024, coluna = "Ano do óbito" ) male_deaths <- sim( conjunto = "obitos", uf = "MS", periodo = 2024, filtros = list(sexo = "Masculino") ) births <- sinasc( uf = "MS", periodo = 2024, coluna = "Ano do nascimento" )
The older sim_*() and sinasc_*() functions remain as compatibility
wrappers, but new code should use the unified functions above.
Hospital, ambulatory and establishment tables follow the same conventions:
admissions <- sih_producao( uf = "MS", conteudo = "Internações", periodo = 2025, filtros = list(carater_atendimento = "Urgência") ) procedures <- sia_producao( uf = "MS", conteudo = "Qtd.aprovada", periodo = 2025 ) beds <- cnes( conjunto = "leitos_internacao", uf = "MS", periodo = "last" ) population <- populacao_residente( uf = "MS", periodo = 2021 )
Use sih_morbidade() when the analysis is diagnosis-oriented rather than
production-oriented:
morbidity <- sih_morbidade( uf = "MS", linha = "Capítulo CID-10", conteudo = "Internações", periodo = 2025 )
The catalog also covers disease-specific SINAN tables, immunization, nutritional surveillance, cancer screening and SUS financing:
dengue <- sinan("dengue", uf = "MS", periodo = 2025) coverage <- pni_imunizacoes( conjunto = "cobertura", uf = "MS" ) mammograms <- siscan( conjunto = "mamografia_residencia", uf = "MS", periodo = 2025 ) nutrition <- sisvan(uf = "MS") financing <- financiamento_sus(uf = "MS")
Results carry a provenance record with the requested system, filters, source URL and retrieval time:
source <- datasus_proveniencia(deaths) str(source)
For a reproducible analysis, save the query arguments together with the
result, request explicit years instead of "last", and record the package
version:
analysis_metadata <- list( package_version = as.character(packageVersion("datasus")), query = list( sistema = "sim", conjunto = "obitos", abrangencia = "uf", periodo = 2024 ), provenance = datasus_proveniencia(deaths) )
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.