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-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
  • 2 replies
  • 691 views
  • 0 likes
  • 2 in conversation