BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
J_CKY
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
J_CKY
Obsidian | Level 7

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

2 REPLIES 2
Tom
Super User Tom
Super User

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);
J_CKY
Obsidian | Level 7

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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