I have the following code. I am doing a remote submit and uploading macro variables to remote server.
The macro variables are sometimes getting resolved and sometimes don't. Can you please help me optimize the code to make it behave more consistently ?
%macro rtlmn1;
%do i=1 %to 2;
%let datep = %sysfunc(intnx(month,&dater.,-1*&i,b));
data _null_;
set sashelp.class(obs=1);
prvmnt&i. = put(&datep.,monyy7.);
put prvmnt&i.;
call symput("prvmnt&i.",prvmnt&i.);
prev_mon&i. = year(&datep.)*100 + month(&datep.);
put prev_mon&i.;
call symput("prmn&i",prev_mon&i.);
run;
%let prmn&i. = &&prmn&i.; /*to remove spaces from values*/
%end;
%mend rtlmn1;
%rtlmn1
%syslput _user_/ remote = remhost;
%macro rtlmn2;
%do i = 1 %to 2;
%syslput i=&i. /remote=remhost;
rsubmit;
proc sql;
create table %nrstr(report_3_part&i.) as
(
select location_id as LocationId , Merchant_family as MerchantFamily ,store_id as StoreId,store_desc as StoreDesc
,zip_code as ZipCode,DMA_name as DmaName ,store_state_nm as StoreState,
sum( case when sales_month = %nrstr(&&prmn&i.) and transaction_type_id = 111 then 1 else 0 end)
as cn1_%nrstr(&&prvmnt&i.) ,
sum ( case when sales_month = %nrstr(&&prmn&i.) and transaction_type_id =111 then transaction_amt else 0 end)
as cnt2_%nrstr(&&prvmnt&i.),
sum( case when sales_month = %nrstr(&&prmn&i.) and transaction_type_id = 222 and reload = 1 then 1 else 0 end)
as cnt3_%nrstr(&&prvmnt&i.),
sum ( case when sales_month = %nrstr(&&prmn&i.) and transaction_type_id = 222 and reload = 1 then transaction_amt else 0 end)
as cnt4_%nrstr(&&prvmnt&i.),
sum ( case when sales_month = %nrstr(&&prmn&i.) and transaction_type_id = 333 and vanilla = 1 then 1 else 0 end)
as cnt5_%nrstr(&&prvmnt&i.),
sum ( case when sales_month = %nrstr(&&prmn&i.) and transaction_type_id = 333 and vanilla = 1 then transaction_amt else 0 end)
as cnt6_%nrstr(&&prvmnt&i.),
sum ( case when sales_month = %nrstr(&&prmn&i.) and transaction_type_id = 444 and green = 1 then 1 else 0 end)
as cnt8_%nrstr(&&prvmnt&i.),
sum ( case when sales_month = %nrstr(&&prmn&i.) and transaction_type_id =444 and green = 1 then transaction_amt else 0 end)
as cnt9_%nrstr(&&prvmnt&i.)
from final_trans_Set
group by Merchant_family , store_id,store_desc,zip_code,DMA_name,location_id,store_state_nm
);
quit ;
endrsubmit;
%end;
%mend rtlmn2;
%syslput _user_/ remote = remhost;
%rtlmn2
NOTE: Line generated by the macro variable "I".
2 &prmn1
-
22
WARNING: Apparent symbolic reference PRMN1 not resolved.
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, BTRIM, INPUT, PUT, SUBSTRING, USER.
What is with the %NRSTR() macro functions?
signon xx sascmd='!sascmd';
%let name1=Judy ;
%let name2=Mary ;
%syslput name1=&name1 / remote=xx;
%syslput name2=&name2 / remote=xx;
%macro xx;
%do i=1 %to 2;
%syslput i=&i / remote=xx;
rsubmit;
proc sql ;
select * from sashelp.class
where name="&&name&i"
;
quit;
endrsubmit;
%end;
%mend xx;
%xx;
signoff xx;
Thanks Tom for your reply.
I was advised to use %nrstr while doing remote submission. Kindly check the following thread - https://communities.sas.com/thread/72192.
I beleive the problem is I am trying to create macro variables in the local session within a macro. They are not getting transported to remote session. That's what my best guess is.
I created macro variables outside macro, through proc sql into syntax, then the call to remote session seems to be going fine.
You might want to try using the logic from the old SYSLPUT autocall macro instead of the new %SYSLPUT statement.
/****************************************************************/
/* SYSLPUT is the opposite of SYSRPUT. SYSLPUT creates a macro*/
/* variable in the remote environment. The user must specify */
/* the macro variable and its value. Optionally, the user */
/* may specify the remote session id; the default session is */
/* the current session. */
/****************************************************************/
%macro syslput612(macvar,macval,remote=);
options nosource nonotes;
%let str=%str(rsubmit &remote;options nosource;)
%nrstr(%let) %str(&macvar = &macval;options source;endrsubmit;);
&str; options notes source;
%mend syslput612;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.