How to mask “OR” in sub-macro with variable list p

2019-08-24 12:57发布

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.

标签: sas sas-macro
1条回答
贼婆χ
2楼-- · 2019-08-24 13:51

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.

查看更多
登录 后发表回答