首页 > 解决方案 > 带有字符串屏蔽的 SAS 假脱机错误

问题描述

这让我现在快疯了。我正在尝试屏蔽在网格安装期间使用的 SAS 计划文件的特定行中的所有特殊字符,该网格安装已拉入数据集:

if test_item = %str(<Machine Id=%'$machine:)&mach_num.%str(' Name=')&mach_name.%str(%'>) then end2 = end1;

日志打印在下面。我看到出现假脱机错误(可能是因为某些内容没有被正确屏蔽),但是MPRINT日志表明宏变量编译已正确执行。

SYMBOLGEN:  Macro variable FUNC_VAR resolves to test
MPRINT(PLAN_FINDER):   data test_plan4;
SYMBOLGEN:  Macro variable FUNC_VAR resolves to test
MPRINT(PLAN_FINDER):   set test_plan3;
MPRINT(PLAN_FINDER):   by ret_sort;
MPRINT(PLAN_FINDER):   retain end2;
388: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 388-185: Expecting an arithmetic operator.
SYMBOLGEN:  Macro variable MACH_NUM resolves to 2
SYMBOLGEN:  Macro variable MACH_NAME resolves to Metadata Server
76: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 76-322: Syntax error, statement will be ignored.

           ________
           49
MPRINT(PLAN_FINDER):   if test_item = <Machine Id='$machine:2' Name='Metadata Server'> then end2 = end1;
MPRINT(PLAN_FINDER):   else if end1 = 1 then end2 = end1 + end2;
MPRINT(PLAN_FINDER):   run;

谁能告诉我我做错了什么?

编码:

%macro test(func_var, mach_num, mach_name);

data &func_var._plan4;
set &func_var._plan3;
by ret_sort;
retain end2;
if test_item = %str(<Machine Id=%'$machine:)&mach_num.%str(' Name=')&mach_name.%str(%'>) then end2 = end1;
else if end1 = 1 then end2 = end1 + end2;
run;

%mend;

%test(test, 2, Metadata Server);

字符串的预期分辨率test_item

<Machine Id='$machine:2' Name='Metadata Server'>

谢谢

标签: sas

解决方案


我不知道你为什么认为你需要掩蔽。它可能比我想象的更复杂,但对我来说似乎也有很多不必要的工作。

这对我来说按预期工作,让我知道它是否适用于你想要做的事情。

test_item = "<Machine Id='$machine:&mach_num.' Name='&mach_name'>"

在数据步骤中测试:

%let mach_name=Metadata Server;
%let mach_num=2;

data test;
test_item = "<Machine Id='$machine:&mach_num.' Name='&mach_name'>" ;
run;

proc print data=test;
run;

结果:

test_item = <Machine Id='$machine:2' Name='Metadata Server'>


推荐阅读