如何使用宏中的 SYSPBUFF 通过变量列表屏蔽子宏中的“OR" [英] How to mask “OR” in sub-macro with variable list passed through using SYSPBUFF in macro
问题描述
我正在使用 SYSPBUFF 将各种数量的参数传递到宏中.具体来说,我正在传递一个状态列表(内部查询)和区域(外部查询).正在使用的州之一是俄勒冈州,缩写为OR",并且该州导致我出错.
I'm using SYSPBUFF to pass through various numbers of parameters into a macro. Specifically, I am passing through a list of states (inner query) and regions (outer query). One of the states being used is Oregon which abbreviates to "OR" and that one state is causing me error.
我之前问了一个几乎相同的问题,并得到了解决问题的答复.但是,现在我在另一个宏中添加了工作宏,它不再起作用了.我在导致内部宏不再工作的外部宏中缺少什么???我应该澄清......它在到达俄勒冈州之前有效.所以宏是功能性的.同样,内部查询正常工作并将 OR 识别为状态值,直到我将其放入外部查询中,然后它停止将 OR 识别为状态值.
I previously asked an almost identical question and got a response that solved the problem. However, now I am adding the working macro within another macro and it no longer works anymore. What am I missing in the outer macro that's causing the inner macro not to work anymore??? I should clarify...it works until it gets to Oregon. So the macro is functional. Again, the inner query works properly and recognized OR as a state value until I put it inside the outer query, then it stops recognizing OR as a state value.
这是我当前的代码:
%macro ALLRG() / parmbuff;
%let r=1;
%let RG=%scan(&SYSPBUFF,&R);
%do %while (%str(&RG)^=);
%syslput NUM=&RG;
%let NUM=&RG;
%syslput STATES=&&STATESR#
%let STATES=&&STATESR#
RSUBMIT;
PROC SQL inobs=1;
connect to oracle
(path=OIGDW ******);
%macro VSNLT() / parmbuff;
%let i=1;
%let ST=%scan(&SYSPBUFF,&I);
%do %while (%str(&ST)^=);
CREATE TABLE PHL_&ST._PROV_05_VRSN AS
select TMS_RUN_TIMESTAMP
from connection to oracle
(SELECT TMS_RUN_TIMESTAMP
from r&NUM._own.&ST._PROV_05);
%let i=%eval(&I+1);
%let ST=%scan(&SYSPBUFF,&I);
%end;
%mend VSNLT;
%VSNLT(&STATES);
disconnect from oracle;
QUIT;
ENDRSUBMIT;
%let r=%eval(&R+1);
%let RG=%scan(&SYSPBUFF,&R);
%end;
%mend ALLRG;
%ALLRG(1,2,3,4,5,6,7,9);
状态表位于区域模式内,因此我必须访问多个模式和表才能获取所有状态.所以我想让外层宏为内层宏设置区域和状态参数.
The state tables are within regional schemas so I have to access multiple shemas and tables to get all the states. So I want the outer macro to set the regional and state parameters for the inner macro.
推荐答案
%superq()
宏函数可能是您想要用来确保宏引用的方法.您可能还想使用 %qscan()
而不是 %scan()
.
The %superq()
macro function is probably what you want to use to insure macro quoting. You might also want to use %qscan()
instead of %scan()
.
%let RG=%qscan(%superq(SYSPBUFF),&R);
我也不清楚您为什么将宏定义推送到远程会话中.可能不需要这种额外的复杂程度.此外,通过 rsubmit 推送宏定义,尤其是在宏中,可能会导致 SAS 弄乱代码的解析.如果您真的需要在那里定义的宏,请通过自动调用或 %include 定义它.如果需要,请使用 proc upload 上传文本.
I am also not clear why you are pushing a macro definition into the remote session. That extra level of complexity might not be needed. Also the pushing of a macro definition via rsubmit, especially within a macro, can cause SAS to mess up the parsing of the code. If you really need a macro defined over there define it via autocall or %include. Upload the text using proc upload if you have to.
这篇关于如何使用宏中的 SYSPBUFF 通过变量列表屏蔽子宏中的“OR"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!