sas字段有html脚本,使用%include运行SAS脚本(Running SAS script using %include)

使用%include运行SAS脚本(Running SAS script using %include)

我是SAS的新手,来自SQL,所以我正在处理他们的差异。

我有一个SAS程序“Master.sas”,其中包括以下内容:

%include "c:\script1.sas";

%include "c:\script2.sas";

%include "c:\script3.sas";

问题是,如果我选择所有这些并运行它,它是按顺序还是并行运行? 例如,如果script2使用在script1中加载的表,它将无法成功运行吗? 好吧,这个例子在我测试时可能听起来很明显,但是如果script1计算变量会发生什么,script2将计算变量或使用它在运行时发现的变量(因为,例如,script2先前已经运行过script1)? 为了澄清,我需要SAS依次运行它们,一个接一个地运行它们。

在SQL中存在“GO”来分离批处理,即:

CREATE TABLE XXXXX

GO

SELECT * FROM XXXXX

GO

如果有人试图用GO运行该脚本,SQL会并行运行它们,在第二个脚本上产生错误,告诉“表XXXXX不存在”。

在上一个完成后,我是否需要在SAS或SAS中使用类似的东西?

提前致谢!

I'm newbie in SAS, coming from SQL, so I'm dealing with them differences.

I have a SAS program "Master.sas" that runs, among other things, something like this:

%include "c:\script1.sas";

%include "c:\script2.sas";

%include "c:\script3.sas";

The question is, if I select all of them and run it, does it run sequentially or in parallel? For example, if script2 uses a table that is loaded in script1, will it fail to run succesfully? Well, that example maybe sound obvious as I tested, but what happens if script1 calculate a variable, script2 will have the variable calculated or uses what it found at run time (because, for example, script2 has runned previously than script1)? Just to clarify, I need that SAS run them sequentially, one after other.

In SQL exists "GO" to separate batch processing, i.e.:

CREATE TABLE XXXXX

GO

SELECT * FROM XXXXX

GO

If someone tries to run that script with out GO, SQL runs them in parallel producing an error on the second script telling that "table XXXXX doesn't exist".

Do I need something similar in SAS or SAS just process next when the previous has finished?

Thanks in advance!

原文:https://stackoverflow.com/questions/39580361

更新时间:2020-01-31 15:37

最满意答案

%include将按顺序运行。 SAS将运行第一个%include ,好像它只是代码中的行,然后点击第二个并执行相同的操作,等等。

SAS相当于GO是RUN ,但在大多数情况下, RUN实际上并不需要包括在内(尽管它被认为是一种很好的做法)。 SAS不会因为你没有运行RUN而以并行模式运行,但这是告诉SAS继续运行并给出它的代码。 但是,这不适用于PROC SQL ; 不支持运行组处理,并立即执行终止的每个语句; 。

有办法让它并行运行; 例如, SUGI 29关于并行处理的实践研讨会展示了如何使用RSUBMIT这样做。 企业指南允许并行处理程序(但不%include在一个程序中%include ),如果您告诉它(但不是默认情况下)。

%include will run things in sequence. SAS will run the first %include as if it were just lines in the code, then hit the second and do the same, etc.

SAS's equivalent of GO is RUN, by the by, though in most cases RUN doesn't actually have to be included (though it's considered a good practice). SAS will not run in parallel mode just because you leave out RUN, but it is what tells SAS to go ahead and run the code that was given it. This does not apply in PROC SQL, however; that does not support run-group processing, and instantly executes each statement terminated by ;.

There are ways to make it run in parallel; for example, this hands-on workshop from SUGI 29 on Parallel Processing shows how to use RSUBMIT to do so. Enterprise Guide allows for parallel processing of programs (but not %includes in one program) if you tell it to (but not by default).

相关问答

SAS,NL-SAS,SATA硬盘的区别 NL-SAS的是采用SAS的磁盘接口和SATA的盘体的综合体。换句话,Near Line (NL) SAS是带有SAS接口的“企业级SATA驱动器”。 SAS是串行scsi,SATA是串行ATA。 SAS 向下兼容SATA SCSI硬盘一般在10Krpm 或15krpm,而ATA硬盘在7.2Krpm 左右。 最初的SAS标准提供了300MB/s(SAS1.0),并计划推出的下一代SAS规范中,速度已经提高到了600MB/s(SAS2.0),SAS被期望最终

...

据我所知,SAS没有一个简单的方法来做到这一点。 你可以把所有的独立变量放到一个宏变量中,然后在模型语句中引用宏变量: proc sql;

select name into :ivars separated by ' '

from dictionary.columns

where libname eq 'WORK' /*library name */

and memname eq 'YOURDATA' /*data set name */

and na

...

感谢Joe在评论中找到了我需要的答案: http://support.sas.com/documentation/cdl/en/lrmeta/63180/HTML/default/viewer.htm#p1k9zipe59ha2an1pq34gu143lay.htm 我使用了本页中的最后一个示例,修改为执行PROC PRINT而不是导出到Excel工作表。 在Enterprise Guide中,我创建了一个新程序,如下所示: /*Connect to the metadata server usi

...

你可以这样做: 列出每个文件夹中的所有.sas文件, 为每个文件创建一个datasetp / infile语句, 在文件的每一行中搜索% include "/sas/dev/compare.sas"; 如果找到行,请在日志中打印文件名和行号 码: %let extension=sas;

%let FolderPath=\\sas\SASDATA\momo\;

%macro check_file_path(f=);

DATA _null_;

infile "&f" dsd ;

length stri

...

我不得不说你对错误的介绍以及你接受的答案感到有点困惑。 根据我的经验, ERROR: Incorrect %INCLUDE statement将显示在第二行之后,而不是之前。 另外,如果宏变量分辨率是问题,那么您将看到以下内容: 903 %LET root = C:\temp;

904

905 %include "&roots\test.sas";

WARNING: Apparent symbolic reference ROOTS not resolved.

WARNING: Physica

...

%include将按顺序运行。 SAS将运行第一个%include ,好像它只是代码中的行,然后点击第二个并执行相同的操作,等等。 SAS相当于GO是RUN ,但在大多数情况下, RUN实际上并不需要包括在内(尽管它被认为是一种很好的做法)。 SAS不会因为你没有运行RUN而以并行模式运行,但这是告诉SAS继续运行并给出它的代码。 但是,这不适用于PROC SQL ; 不支持运行组处理,并立即执行终止的每个语句; 。 有办法让它并行运行; 例如, SUGI 29关于并行处理的实践研讨会展示了如何使

...

有%SYMEXIST(macro-var-name)变量%SYMEXIST(macro-var-name)宏函数来查看宏变量是否存在,但是你不能在打开时写入%IF ,所以你必须将%IF语句包含在其他宏中。 您可能最终编写一个宏只是为了将您的代码包装在如下所示的源文件中。 这不是很好,但如果需要警卫,你可以用这个来解决问题。 %macro wrapper;

%if %symexist(foo_defined) %then %return;

%macro foo;

%global fo

...

%include就像在外部文件上点击F3一样。 它将尝试编译并执行文本文件中的所有内容。 所以,如果你打开mcompilenote=all并且你的程序是: %macro test;

%put test macro;

%mend;

%test;

日志将显示为: 8 %macro test;

9 %put test macro;

10

11 %mend;

NOTE: The macro TEST completed compilation without errors.

...

您可以通过子进程调用将其他参数传递给SAS,但您还需要记住的重要事项是: 您需要告诉SAS在哪里可以找到AUTOEXEC文件 您需要告诉SAS在哪里可以找到配置文件 我有一个用于调用SAS脚本的shell脚本,调用如下所示: sas -config $SAS_CONFIG -autoexec $SAS_AUTOEXEC $SAS_CODE/$1 所以你的调用应该是这样的: subprocess.call(['C:\Program Files\SAS\SASFoundation\9.2\sas.ex

...

我不知道是否有一种真正干净的解决方法。 问题是连接到SQL会将%include传递给SQL解析器,这与您想要的相比当然是不正确的。 但是,它将正确解析宏和宏变量,因此您可以将SQL命令读入宏变量并以此方式使用它。 一种方法是在下面。 filename tempfile temp; *imaginary file - this would be your SQL script;

data _null_; *creating a mocked up SQL script fi

...

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值