Hi experts,
I am struggling to make a macro call that includes semicolons inside the parameter.
DATA _NULL_; SET WORK.HAVE END=eof ; call execute('%MyMacro('||list_coordinates||')'); RUN;
My 'list_coordinates' parameter is something like 51.95179749,7.99066114;51.17936325,6.74318409;51.33995819,4.31496429.
I am getting the following error each time that found a semicolon:
Statement is not valid or it is used out of proper order
Thanks
The simplest thing it to modify the macro to accept quotes around the parameter value. It can always use %SYSFUNC() to call DEQUOTE() if they need to be removed.
43 DATA _NULL_; 44 SET HAVE END=eof ; 45 call execute(cats('%nrstr(%MyMacro)(',quote(trim(list_coordinates),"'"),')')); 46 RUN; NOTE: There were 1 observations read from the data set WORK.HAVE. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds NOTE: CALL EXECUTE generated line. 1 + %MyMacro('51.95179749,7.99066114;51.17936325,6.74318409;51.33995819,4.31496429') X='51.95179749,7.99066114;51.17936325,6.74318409;51.33995819,4.31496429'
But you could also add macro quoting in the generated call.
47 DATA _NULL_; 48 SET HAVE END=eof ; 49 call execute(cats('%nrstr(%MyMacro(%nrstr(',list_coordinates,')))')); 50 RUN; NOTE: There were 1 observations read from the data set WORK.HAVE. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds NOTE: CALL EXECUTE generated line. 1 + %MyMacro(%nrstr(51.95179749,7.99066114;51.17936325,6.74318409;51.33995819,4.31496429)) X=51.95179749,7.99066114;51.17936325,6.74318409;51.33995819,4.31496429
My personal advice: change the macro so that it accepts less critical delimiters, e.g. pipes (|).
Then replace the uncritical delimiter in the macro, right where you make the web call. Use the TRANSLATE function for this.
Can you make a full example that replicates the problem? I tried this simple test:
%macro mymacro(x) ;
%put &x ;
%mend ;
data have ;
list_coordinates="51.95179749 7.99066114;51.17936325 6.74318409;51.33995819 4.31496429" ;
run ;
DATA _NULL_;
SET WORK.HAVE END=eof ;
call execute('%MyMacro('||list_coordinates||')');
RUN;
and did not get the error message you're getting. My guess is the error is coming from some code inside your macro. You may need to add macro quoting. (Note I removed the commas from list_coordinates, because they cause a different error message). If you could post full example code, and include the log, that would be helpful.
The simplest thing it to modify the macro to accept quotes around the parameter value. It can always use %SYSFUNC() to call DEQUOTE() if they need to be removed.
43 DATA _NULL_; 44 SET HAVE END=eof ; 45 call execute(cats('%nrstr(%MyMacro)(',quote(trim(list_coordinates),"'"),')')); 46 RUN; NOTE: There were 1 observations read from the data set WORK.HAVE. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds NOTE: CALL EXECUTE generated line. 1 + %MyMacro('51.95179749,7.99066114;51.17936325,6.74318409;51.33995819,4.31496429') X='51.95179749,7.99066114;51.17936325,6.74318409;51.33995819,4.31496429'
But you could also add macro quoting in the generated call.
47 DATA _NULL_; 48 SET HAVE END=eof ; 49 call execute(cats('%nrstr(%MyMacro(%nrstr(',list_coordinates,')))')); 50 RUN; NOTE: There were 1 observations read from the data set WORK.HAVE. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds NOTE: CALL EXECUTE generated line. 1 + %MyMacro(%nrstr(51.95179749,7.99066114;51.17936325,6.74318409;51.33995819,4.31496429)) X=51.95179749,7.99066114;51.17936325,6.74318409;51.33995819,4.31496429
Hi experts,
Thanks for the suggestions. I made it work using @Tom first suggestion calling the macro parameter between quotes.
DATA _NULL_; SET HAVE END=eof ; call execute(cats('%nrstr(%MyMacro)(',quote(trim(list_coordinates),"'"),')')); RUN;
Then I 'dequote' the parameter inside my macro and use the new one.
%macro MyMacro(list_coordinates); %let new_coordinates_list = %sysfunc(dequote(&list_coordinates)); /*Call my webservice using new_coordinates_list*/ %mend MyMacro;
Thanks for your time.
You probably need to use %Qsysfunc to add macro quoting to the result.
55 %let x=%sysfunc(dequote('aa;bb')); NOTE: Line generated by the macro function "SYSFUNC". 1 aa;bb -- 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 56 %put &=x; X=aa 57 %let x=%qsysfunc(dequote('aa;bb')); 58 %put &=x; X=aa;bb
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 16. 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: