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 §.(&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?
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 §.(&cat_num.) ;
data test_out;
set source (where = (category_id in ("&CAT_NUM")));
run;
endrsubmit;
%mend;
%test(CAT1);
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 §.(&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);
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 §.(&cat_num.) ;
data test_out;
set source (where = (category_id in ("&CAT_NUM")));
run;
endrsubmit;
%mend;
%test(CAT1);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.