sql-server-2005 – SAS读取sql server 2005中的位数据类型

我有一个sql server 2005数据库,其中包含一个数据类型为bit的列.当我查看sql server management studio中的数据时,我看到列值为0或1,当我使用SAS时,我看到0或-1,就像SAS正在否定1值.有人对此有解释吗?谢谢.

解决方法

我估计你必须使用libname oledb从SAS连接到sql Server.我可以在这里复制你的问题: –

sql Server代码生成虚拟数据

create table dbo.tbl (
    tblId           int identity(1,1)   not null
                    constraint pk_tbl_tblId primary key,bool        bit not null,)
go

insert into dbo.tbl(bool) values(0)
insert into dbo.tbl(bool) values(1)

使用OLEDB的SAS代码

libname imm oledb provider=sqloledb
        properties=(
            "Integrated Security"=sspI
            "Persist Security Info"=False
            "Initial Catalog"=test
            "Data Source"=localhost
        );

proc print data=imm.tbl; run;

打印出来的是: –

Obs          tblId    bool

1              1      0
2              2     -1

使用PROC sql的SAS代码

似乎使用PROC sql应该解决您的问题.

proc sql noprint;
    connect to sqlservr (
        server='localhost' 
        database='test' 
        'Integrated Security'='sspI' 
        'Persist Security Info'='False'
    );

    create table test as
    select *
    from connection to sqlservr (
        select * from dbo.tbl
    );

    disconnect from sqlservr;
quit;

proc print data=test; run;

打印出来的是: –

Obs          tblId    bool

1              1      0
2              2      1

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...