BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
FP12
Obsidian | Level 7
%macro process_8
	(ext_output,
	transf_output_gr,
	transf_output_se,
	transf_output_su,
	rest_output_gr,
	rest_output_se,
	rest_output_su);

 

data _null_;
if "&HUIT" = "YES" then call execute('%nrstr(%process_8(
												ext_output = EXT_8, 
												transf_output_gr = TRANSF_8_GR, 
												transf_output_se = TRANSF_8_SE,
												transf_output_su = TRANSF_8_SU, 
												rest_output_gr = REST_8_GR, 
												rest_output_se = REST_8_SE, 
												rest_output_su = REST_8_SU)');
run;

Hi all,

 

I defined a macro process_8, and then I call it like shown.

When I do this I have the warning in title.


I know I can manage it by removing the left part of the equal, but for readibility question I prefer to keep it.

How can I manage it?

 

Thanks,

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

You would eliminate some complications and improve accuracy if you were to use a macro instead of CALL EXECUTE.  And you would definitely eliminate the problem about the length of a quoted string.

 

You do have to decide whether you are using position parameters (as in the macro definition) or keyword parameters (as in the call to the macro).  But the structure would be pretty simple:

 

%macro run_this;

 

   %if "&HUIT" = "YES" %then %do;

        %process_8   (        .... any sort of spacing and indentation that you please .....       )

   %end;

 

%mend run_this;

 

%run_this

View solution in original post

4 REPLIES 4
Astounding
PROC Star

You would eliminate some complications and improve accuracy if you were to use a macro instead of CALL EXECUTE.  And you would definitely eliminate the problem about the length of a quoted string.

 

You do have to decide whether you are using position parameters (as in the macro definition) or keyword parameters (as in the call to the macro).  But the structure would be pretty simple:

 

%macro run_this;

 

   %if "&HUIT" = "YES" %then %do;

        %process_8   (        .... any sort of spacing and indentation that you please .....       )

   %end;

 

%mend run_this;

 

%run_this

ballardw
Super User

First I believe your data step has unbalanced (. and is missing the ; for the macro call. Removing most of the parameters so it is easier to read you call execute reduces to for readability:

call execute('%nrstr(%process_8(	ext_output = EXT_8)');

So call execute is likely grabbing way more code than you expect, such as the Run; and more. I am not sure that you actually need the %nrstr as if the macro call is within single quotes it should not try to expand during the data step.

 

 

Another potential issue could just be the way you have laid out the codel. Note that there are 7 lines to your call execute and the system call may be exanding about 60? tabs to around 300 characters.

The first thing I would try would be to not make the code "pretty" with all of the indents for the parameters

data _null_;
   if "&HUIT" = "YES" then call execute('%process_8(	ext_output = EXT_8,transf_output_gr = TRANSF_8_GR, 
   transf_output_se = TRANSF_8_SE,transf_output_su = TRANSF_8_SU, rest_output_gr = REST_8_GR, 
   rest_output_se = REST_8_SE, rest_output_su = REST_8_SU);');
run;

Often when I'm working with call execute I have a long string variable in the code and will assign long values to that variable so the

 

call execute is shorter and easier to manage:

 

data _null_;
   length longstr $ 200;
   longstr = '	ext_output = EXT_8,transf_output_gr = TRANSF_8_GR, 
   transf_output_se = TRANSF_8_SE,transf_output_su = TRANSF_8_SU, rest_output_gr = REST_8_GR, 
   rest_output_se = REST_8_SE, rest_output_su = REST_8_SU';
   if "&HUIT" = "YES" then call execute('%process_8(	'||longstr||');');
run;

which if the Longstr may be build out of variables from a data set gets much simpler than embedding all the concatenations likely needed into the call execute line itself.

 

FP12
Obsidian | Level 7

Well, thanks, it worked.

But I am not sure it's a good practice, but whatever ^^

ballardw
Super User

@FP12 wrote:

Well, thanks, it worked.

But I am not sure it's a good practice, but whatever ^^


If that is in response to my "string" approach it is purely style.

 

"Good practice" may have different definitions in different shops. But If it helps me keep from creating mismatched () or quotes I'm for it.

 

Most of the time I use call execute is where a a data set contains multiple values that I'm doing the same thing for so building strings using multiple variables is much cleaner when not in the middle of a call execute statement with the associated extra () and likely ;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 5394 views
  • 1 like
  • 3 in conversation