使用 ReadStat 从 SAS、Stata 和 SPSS 读取数据集
维护者: mettekou
安装和加载
INSTALL read_stat FROM community;
LOAD read_stat;
示例
-- Read a SAS `.sas7bdat` or `.xpt` file
FROM read_stat('sas_data.sas7bdat');
FROM read_stat('sas_data.xpt');
-- Read an SPSS `.sav`, `.zsav`, or `.por` file
FROM read_stat('spss_data.sav');
FROM read_stat('compressed_spss_data.zsav');
FROM read_stat('portable_spss_data.por');
-- Read a Stata .dta file
FROM read_stat('stata_data.dta');
-- If the file extension is not `.sas7bdat`, `.xpt`, `.sav`, `.zsav`, `.por`, or `.dta`,
-- use the `read_stat` function for the right file type with the `format` parameter:
FROM read_stat('sas_data.other_extension', format = 'sas7bdat');
FROM read_stat('sas_data.other_extension', format = 'xpt');
-- SPSS `.sav` and `.zsav` can both be read through the format `'sav'`
FROM read_stat(
'spss_data_possibly_compressed.other_extension',
format = 'sav'
);
FROM read_stat('portable_spss_data.other_extension', format = 'por');
FROM read_stat('stata_data.other_extension', format = 'dta');
-- Override the character encoding with an `iconv`` encoding name,
-- see https://gnu.ac.cn/software/libiconv/
CREATE TABLE other_data AS FROM read_stat('latin1_encoded.sas7bdat', encoding = 'iso-8859-1');
关于 read_stat
用法
参数
名称 | 描述 | 类型 | 默认值 |
---|---|---|---|
格式 |
输入文件的格式,当其扩展名未指明时,可以是 'sas7bdat' , 'xpt' , 'sav' , 'por' , 或 'dta' |
VARCHAR |
NULL |
编码 |
输入文件的字符编码,由 iconv 定义,参见 https://gnu.ac.cn/software/libiconv/ |
VARCHAR |
NULL |
新增函数
函数名 | 函数类型 | 描述 | 注释 | 示例 |
---|---|---|---|---|
read_stat | 表 | NULL | NULL |