BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
MM88
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

View solution in original post

7 REPLIES 7
MM88
Calcite | Level 5
Hi @Kurt_Bremser,

Semicolon is not my delimiter choice.

Inside the macro I call a webservice that receive the coordinates list separated by semicolons.

Any advice?
Quentin
Super User

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 Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
Tom
Super User Tom
Super User

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

MM88
Calcite | Level 5

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.

Tom
Super User Tom
Super User

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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 7 replies
  • 1368 views
  • 1 like
  • 4 in conversation