SAS Proc SQL 数据库表插入

发布于 2024-07-25 04:53:52 字数 499 浏览 8 评论 0原文

使用 SAS 的 Proc SQL,有没有办法将 SAS 数据集中的记录插入到打开的 SQL Server 连接中的表中? 像这样的东西(不起作用):

proc sql exec;
    connect to sqlservr as DataSrc (server=my-db-srvr database=SasProcSqlTest);

    create table Items as select * from connection to DataSrc (
        SELECT * FROM tblItem
    );

    update Items
    set Name = Name + Name,
        Value * 2;

    insert into tblItem (Name, Value)
    select Name, Value
    from Items;

    disconnect from DataSrc;quit;run;
quit;
run;

Using SAS's Proc SQL, is there a way to insert records from a SAS Dataset into a table in the open SQL Server connection? Something like this (which doesn't work):

proc sql exec;
    connect to sqlservr as DataSrc (server=my-db-srvr database=SasProcSqlTest);

    create table Items as select * from connection to DataSrc (
        SELECT * FROM tblItem
    );

    update Items
    set Name = Name + Name,
        Value * 2;

    insert into tblItem (Name, Value)
    select Name, Value
    from Items;

    disconnect from DataSrc;quit;run;
quit;
run;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一向肩并 2024-08-01 04:53:52

据我所知,使用 SQL 传递会将您限制在数据库服务器上。 SAS 文档指出,您应该最好创建对数据库的库引用,然后像对待 SAS 表一样对待数据库表。 在你的情况下,这意味着只是普通的 proc sql。 这至少应该适用于最新的 SAS 版本,但对于大型表来说并不是最佳选择。

为了避免这种情况,我们所做的就是

  1. 在临时数据库中创建一个表 - 该表不应该是特定于会话的
  2. 使用 proc append 将数据从 SAS 批量加载到创建的表中
  3. 执行传递更新
  4. 将表删除到临时数据库中。

To my knowledge, using pass through SQL constrains you to the database server. The SAS documentantion says that you should preferrably create a library reference to the database and then treat the database tables just like SAS tables. In your case this means just normal proc sql. This should work at least in the latest SAS versions, but for large tables is not optimal.

What we've done to circumvent this is

  1. Create a table in a temporary database - the table should not be session-specific
  2. Bulk load data from SAS to the created table, using proc append
  3. Do the pass through update
  4. Drop the table in temp db.
穿透光 2024-08-01 04:53:52

您可以在打开的连接中执行您想要的操作..

创建关联的 libname..

libname datasrc_lib sqlservr server=my-db-srvr database=SasProcSqlTest;

proc sql exec;
    connect to sqlservr as DataSrc (server=my-db-srvr database=SasProcSqlTest);

        create table Items as select * from connection to DataSrc (
                SELECT * FROM tblItem
        );

    update Items
    set Name = Name + Name,
        Value * 2;

    insert into datasrc_lib.some_temp_table select * from items;


    execute( insert into tblItem where select * from some_temp_table ) by DataSrc ;

    execute( drop table some_temp_table ) by DataSrc ;


    disconnect from DataSrc;quit;run; quit; run;

上面的伪代码应该让您了解它应该如何工作。 您可能还需要在 proc sql 中创建“some_temp_table”或者有一个可用的永久临时表。

You can do what you want within an open connection..

create an associated libname..

libname datasrc_lib sqlservr server=my-db-srvr database=SasProcSqlTest;

proc sql exec;
    connect to sqlservr as DataSrc (server=my-db-srvr database=SasProcSqlTest);

        create table Items as select * from connection to DataSrc (
                SELECT * FROM tblItem
        );

    update Items
    set Name = Name + Name,
        Value * 2;

    insert into datasrc_lib.some_temp_table select * from items;


    execute( insert into tblItem where select * from some_temp_table ) by DataSrc ;

    execute( drop table some_temp_table ) by DataSrc ;


    disconnect from DataSrc;quit;run; quit; run;

The above pseudo code should give you an idea of how it should work. You may need to create the "some_temp_table" in the proc sql as well or have a permanent staging table available.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文