并行处理时共享变量 [英] Sharing variables when parallel processing

查看:12
本文介绍了并行处理时共享变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了一个进程,并行处理 8 个程序以提取大量数据.但是,我必须维护每个变量中的所有变量(这是每月一次).

I have setup a process that parallel processes 8 programs to pull a lot of data. However, I have to maintain all of the variables in each one going forward (this is a monthly thing).

有没有办法创建一个包含所有变量的主程序并在运行时跨程序共享它们?我知道每个程序都使用自己的 SAS 实例,所以我认为没有.

Is there a way to create 1 master program with all of the variables and share them across programs when running? I understand each program uses its own instance of SAS so I am thinking no.

推荐答案

如您所见,不同的 SAS 程序不会自动共享变量,但您可以显式传递它们:

As you correctly notice, the different SAS programs do not share variables automatically, but you can pass them explicitly:

  • 通过环境变量传递它们(当您的参数很少时,这尤其有用,例如报告日期).

  • By passing them through environment variables (this is especially useful when you have few parameters, like the report date).

  • 本例中的启动程序可以是一个简单的 shell 脚本,例如在 *nix 中:

  • The launcher program in this case can be a simple shell script, e.g. in *nix:

export REPORT_DATE=20190701
sas -sysin program_a.sas

  • 或者,在 SAS 中,您可以使用 systask 命令 执行子 SAS 会话
  • 您可以从子会话中通过 %sysget 检索参数值:

  • Or, from SAS, you can use systask command to execute the child SAS session
  • From the child session you can retrieve the parameter value via %sysget:

    %let REPORT_DATE = %sysget(REPORT_DATE);
    

  • 按照评论中的建议,将参数存储在共享位置(例如数据集中).

    As suggested in the comments, by storing the parameters in a shared location (e.g. in a dataset).

    • 在父会话中:

    • In the parent session:

    data sharedlib.params;
        REPORT_DATE = "&REPORT_DATE";
    run;
    

  • 在子会话中:

  • In the child session:

    proc sql noprint;
        select REPORT_DATE /*format XXX. as necessary*/ into :REPORT_DATE
        from sharedlib.params;
    quit;
    

  • 如果您使用 SAS/CONNECT 管理子会话(即 signonrsubmit),您可以通过 %sysrput

    If you use SAS/CONNECT to manage the child sessions (i.e. signon and rsubmit), you can pass the variables via %sysrput

    这篇关于并行处理时共享变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆