How to mask “OR” in sub-macro with variable list passed through using SYSPBUFF in macro

痴心易碎 提交于 2020-01-06 08:28:31

问题


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.

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.

Here is my current code:

%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.


回答1:


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);

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.



来源:https://stackoverflow.com/questions/55386379/how-to-mask-or-in-sub-macro-with-variable-list-passed-through-using-syspbuff-i

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!