DATA Step, Macro, Functions and more

Macro variable remote server funnies

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

Macro variable remote server funnies

Hi, I am trying to run a macro, depending on the macro variable, conditionally setup a dependent macro variable.

 

But something went wrong

 

%macro test(sect);
rsubmit;
options compress = binary;
%if %upcase(&SECT) = CAT1%then %let CAT_NUM = 001; 
  %else %if %upcase(&SECT) = CAT2 %then   %let CAT_NUM = 002; 

%put WAR%str(NING:) now running for &sect.(&cat_num.) ;
	data test_out;
	set source (where = (category_id in ("&CAT_NUM")));
    run;
endrsubmit;
%mend; 

%test(CAT1);

Somehow, the %PUT statement managed to populate the CAT_NUM as '001'

 

 

Whereas in the data step, CAT_NUM macro variable failed to resolve. 

 

I tested this without the rsubmit bound and it seems to work.  However, I need this to be submitted the remote server and the macro have to be define locally. How could resolve this?


Accepted Solutions
Solution
‎11-17-2017 11:22 AM
Contributor
Posts: 22

Re: Macro variable remote server funnies

Hi Tom,

 

tried with your modified code.  Still getting the same error.

 

But I have get it to work by moving the whole %if %then %else condition, as well as the syslput, out of the REMOTE/SUBMIT bound.

 

Thanks for your help.

 

Here is my solution:

%macro test(sect);
%if %upcase(&SECT) = CAT1 %then %let CAT_NUM = 001; 
%else %if %upcase(&SECT) = CAT2 %then %let CAT_NUM = 002; 
* Push macro variable to remote session ;
%syslput CAT_NUM=&cat_num;

rsubmit;
options compress = binary;
%put WAR%str(NING:) now running for &sect.(&cat_num.) ;
data test_out;
  set source (where = (category_id in ("&CAT_NUM")));
run;
endrsubmit;
%mend; 

%test(CAT1);

View solution in original post


All Replies
Super User
Super User
Posts: 7,844

Re: Macro variable remote server funnies

Why would it work? 

Your macro is running on your local machine. The SAS code that it generates between the RSUBMIT/ENDRSUBMIT statements will run on the remote machine.

If you want the code on the remote machine to reference a macro variable then you need to define the macro variable on the remote machine.

 

%macro test(sect);
rsubmit;
options compress = binary;
%if %upcase(&SECT) = CAT1 %then %let CAT_NUM = 001; 
%else %if %upcase(&SECT) = CAT2 %then %let CAT_NUM = 002; 

%put WAR%str(NING:) now running for &sect.(&cat_num.) ;
%* Push macro variable to remote session ;
%syslput CAT_NUM=&cat_num;

data test_out;
  set source (where = (category_id in ("&CAT_NUM")));
run;
endrsubmit;
%mend; 

%test(CAT1);
Solution
‎11-17-2017 11:22 AM
Contributor
Posts: 22

Re: Macro variable remote server funnies

Hi Tom,

 

tried with your modified code.  Still getting the same error.

 

But I have get it to work by moving the whole %if %then %else condition, as well as the syslput, out of the REMOTE/SUBMIT bound.

 

Thanks for your help.

 

Here is my solution:

%macro test(sect);
%if %upcase(&SECT) = CAT1 %then %let CAT_NUM = 001; 
%else %if %upcase(&SECT) = CAT2 %then %let CAT_NUM = 002; 
* Push macro variable to remote session ;
%syslput CAT_NUM=&cat_num;

rsubmit;
options compress = binary;
%put WAR%str(NING:) now running for &sect.(&cat_num.) ;
data test_out;
  set source (where = (category_id in ("&CAT_NUM")));
run;
endrsubmit;
%mend; 

%test(CAT1);
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 53 views
  • 0 likes
  • 2 in conversation