在 SAS 中同时运行多个查询

发布于 2024-09-15 12:18:24 字数 517 浏览 3 评论 0原文

我有 36 个完全独立的查询,我需要定期运行,如果一次可以运行 3 个,那么速度会快得多(如果我们尝试一次执行超过 3 个,数据库会取消我们的查询),而不是每个查询都等待以便前面的内容完成。

我想做这样的事情

/* Some prep code here*/

/* Launch batch 1 containing queries 1-12*/
/* Immediately launch batch 2 (13-24) without waiting for 1-12 to finish*/
/* Immediately launch batch 3 (25-36)*/

/* Wait until all 3 batches are done and run some conclusion code*/

或者,如果可能的话,只给它 36 个查询,并让它一次运行多个,确保在任何给定时间和任何一个完成时运行的次数不超过 3 个,只需添加堆栈中的下一个。

使用 SAS 可以做到这一点吗?

谢谢

I have 36 completely independent queries I need to run on a regular bases which would go much faster if they could run 3 at a time (the database cancels our queries if we try and do more than 3 at a time) instead of each one waiting for the previous to finish.

I would like to do something like this

/* Some prep code here*/

/* Launch batch 1 containing queries 1-12*/
/* Immediately launch batch 2 (13-24) without waiting for 1-12 to finish*/
/* Immediately launch batch 3 (25-36)*/

/* Wait until all 3 batches are done and run some conclusion code*/

Or, if possible, just give it the 36 queries all together and have it run multiple at a time making sure to not have more than 3 running at any given time and any time one finishes, just add the next one from the stack.

Is this possible to do using SAS?

Thanks

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

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

发布评论

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

评论(3

茶色山野 2024-09-22 12:18:24

我假设您有一个 SAS 服务器,并且您正在从本地计算机启动查询。
(如果您不这样做并且在本地工作,这不是问题,您可以重新提交到本地计算机上的生成器)
即使使用 SAS/Base,也可以通过在单个代码中具有三个连接来同时启动 3 个查询。
我在这里假设您不想共享工作库并且是完全独立的查询

option autosignon=yes;
option sascmd="!sascmd";

* some random data;
data prova1;
do i=1 to 20000000;
    x=rand('UNIFORM');
    output;
end;
run;

data prova2;
do i=1 to 20000000;
    y=rand('UNIFORM');
    output;
end;
run;
*open connection to the server ;

options comamid=tcp;
filename rlink "D:\SAS\SASFoundation\9.2\connect\saslink\tcpwin.scr";
%LET host1=nbsimbol59;
%LET host2=nbsimbol59;

signon remote=host1 script=rlink;
signon remote=host2 script=rlink;

rsubmit process=host1 wait=no inheritlib=(work=cwork);; 

   proc sort data=cwork.prova1 out=cwork.r1;
     by x;
   run;

   proc sort data=cwork.r1 out=cwork.r1a;
     by i;
   run;


endrsubmit;


rsubmit process=host2 wait=no inheritlib=(work=cwork);; 

   proc sort data=cwork.prova2 out=cwork.r2;
     by y;
   run;

   proc sort data=cwork.r2 out=cwork.r2a;
     by i;
   run;

endrsubmit;

/* Wait for both tasks to complete. */
waitfor _ALL_ host1 host2;

data r9;
     merge r1a (in=a) r2a (in=b);
    by i;
    if a and b;
    run;


signoff host1;
signoff host2;

此示例代码的唯一问题是它将等待两个任务结束并且 atm 不会想到一种方法让它尽快启动另一个查询一个结束了,但我相信也许有办法解决它。

现在,使用此代码,您可以轻松地一次启动 3 个查询,然后当它们结束时再启动 3 个查询,依此类推。
对于您的其他要求,我会考虑一下:)

I'm assuming you have a SAS server and from your local machine you're launching the queries.
(If you dont and work locally its not a problem you can do a rsubmit to a spawner you have on your local machine)
Even with SAS/Base its possible to have 3 queries launch at the same time by having in a single code three connection.
I'm assuming here you dont want to share work libraries and are completely independent queries

option autosignon=yes;
option sascmd="!sascmd";

* some random data;
data prova1;
do i=1 to 20000000;
    x=rand('UNIFORM');
    output;
end;
run;

data prova2;
do i=1 to 20000000;
    y=rand('UNIFORM');
    output;
end;
run;
*open connection to the server ;

options comamid=tcp;
filename rlink "D:\SAS\SASFoundation\9.2\connect\saslink\tcpwin.scr";
%LET host1=nbsimbol59;
%LET host2=nbsimbol59;

signon remote=host1 script=rlink;
signon remote=host2 script=rlink;

rsubmit process=host1 wait=no inheritlib=(work=cwork);; 

   proc sort data=cwork.prova1 out=cwork.r1;
     by x;
   run;

   proc sort data=cwork.r1 out=cwork.r1a;
     by i;
   run;


endrsubmit;


rsubmit process=host2 wait=no inheritlib=(work=cwork);; 

   proc sort data=cwork.prova2 out=cwork.r2;
     by y;
   run;

   proc sort data=cwork.r2 out=cwork.r2a;
     by i;
   run;

endrsubmit;

/* Wait for both tasks to complete. */
waitfor _ALL_ host1 host2;

data r9;
     merge r1a (in=a) r2a (in=b);
    by i;
    if a and b;
    run;


signoff host1;
signoff host2;

Only problem with this sample code is that it will wait both task to end and atm it doesnt come to mind a way to have it launch another query as soon as one ends but i believe it may be possible to have some way around it.

For now with this code you can easily launch 3 queries at a time, then when they end up 3 more and so on.
For your other request i'll think about it :)

五里雾 2024-09-22 12:18:24

在某些平台上(当然是 Windows 和 UNIX),如果配置允许 SAS 会话与操作系统交互,则 SYSTASK 语句使您能够执行、列出或终止异步任务。结合 WAITFOR 语句,您可以执行以下操作:

systask command "sas prog1.sas" taskname=sas1;
systask command "sas prog2.sas" taskname=sas2;
systask command "sas prog3.sas" taskname=sas3;
waitfor _all_ sas1 sas2 sas3; /* suspend current session until the three jobs are finished */

请参阅 SYSTASKWAITFOR 语句(适用于 Windows 平台)。

On some platforms (Windows and UNIX for sure), if the configuration allows your SAS session to interact with the OS, then the SYSTASK statement gives you the ability to executes, lists, or terminates asynchronous tasks. Combined with the WAITFOR statement, you can do something like this:

systask command "sas prog1.sas" taskname=sas1;
systask command "sas prog2.sas" taskname=sas2;
systask command "sas prog3.sas" taskname=sas3;
waitfor _all_ sas1 sas2 sas3; /* suspend current session until the three jobs are finished */

See documentation on SYSTASK and WAITFOR statements (for the Windows Platform).

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