BookmarkSubscribeRSS Feed
rajat051984
Fluorite | Level 6

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.

3 REPLIES 3
Tom
Super User Tom
Super 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;

rajat051984
Fluorite | Level 6

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.

Tom
Super User Tom
Super User

You might want to try using the logic from the old SYSLPUT autocall macro instead of the new %SYSLPUT statement.

See this discussion 

/****************************************************************/

/*  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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1293 views
  • 0 likes
  • 2 in conversation