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.

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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