DATA Step, Macro, Functions and more

what is the wrong with my macro code below?

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

what is the wrong with my macro code below?

Hi Forum,

Could you please help me to figure out what is the wrong with my macro code below , i have created macro variable at the end .

%macro outer_reconcil(dataname =%str() );
proc sort data = comment_&dataname;
  by subject aespid;
run;
%mend outer_reconcil;

%outer_reconcil(dataname = %str(Event_not_rec));

still getting


15355  %outer_reconcil(dataname = %nrbquote(Event_not_rec));
MLOGIC(OUTER_RECONCIL):  Beginning execution.
MLOGIC(OUTER_RECONCIL):  Parameter DATANAME has value  Event_not_rec
SYMBOLGEN:  Macro variable DATANAME resolves to Event_not_rec
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted
            for printing.
NOTE: Line generated by the macro variable "DATANAME".
1       comment_Event_not_rec
                -------------
                22
                 -------------
                 202
ERROR: File WORK.COMMENT_.DATA does not exist.
MPRINT(OUTER_RECONCIL):   proc sort data = comment_Event_not_rec by subject aespid;
MPRINT(OUTER_RECONCIL):   run;

ERROR 22-322: Syntax error, expecting one of the following: ;, (, ASCII, BUFFNO, DANISH, DATA,
              DATECOPY, DETAILS, DIAG, DUPOUT, EBCDIC, EQUALS, FINNISH, FORCE, IN, ISA, L, LEAVE,
              LIST, MESSAGE, MSG, NATIONAL, NODUP, NODUPKEY, NODUPKEYS, NODUPLICATE, NODUPLICATES,
              NODUPREC, NODUPRECS, NODUPS, NOEQUALS, NORWEGIAN, NOTHREADS, NOUNIKEY, NOUNIKEYS,
              NOUNIQUEKEY, NOUNIQUEKEYS, NOUNIQUEREC, NOUNIQUERECS, NOUNIREC, NOUNIRECS, OSA, OUT,
              OVERWRITE, PAGESIZE, PRESORTED, PSIZE, REVERSE, SIZE, SORTSEQ, SORTSIZE, SORTWKNO,
              SWEDISH, T, TAGSORT, TECH, TECHNIQUE, TESTHSI, THREADS, UNIOUT, UNIQUEOUT, WKNO,
              WORKNO.

ERROR 202-322: The option or parameter is not recognized and will be ignored.

NOTE: The SAS System stopped


Accepted Solutions
Solution
‎12-22-2014 06:41 AM
Super User
Posts: 9,681

Re: what is the wrong with my macro code below?

Why use %str() ? It makes them in different compile level  .

View solution in original post


All Replies
Solution
‎12-22-2014 06:41 AM
Super User
Posts: 9,681

Re: what is the wrong with my macro code below?

Why use %str() ? It makes them in different compile level  .

New Contributor
Posts: 2

Re: what is the wrong with my macro code below?

HI Xia , Thanks for the Answare .

could you please let me know why not to use %str

Super User
Posts: 9,681

Re: what is the wrong with my macro code below?

%str(Event_not_rec)  is in a compile stage .  comment_  is in another compile stage . when you put them together   comment_%str(Event_not_rec)   ,  SAS would compile them in the different stage . That is reason why you got ERROR .


To clarify something more .  %str() %nrstr() %superq()  ......... they are all macro variable mask function , they will add mask character around macro variable . For this example , you can take it as   \bEvent_not_rec\b   ,   \b is the mask character , therefore the real code generated in compile engine is      comment_\bEvent_not_rec\b , so you get the ERROR message . if you don't put %str() around it , it will generate code     comment_Event_not_rec  , that is right code we need .



Xia Keshan

Message was edited by: xia keshan

Super User
Super User
Posts: 6,500

Re: what is the wrong with my macro code below?

Because you quoted the macro string in the call it is confusing the parser.  It sees two tokens instead of one.

Your macro can adjust for this by adding an %UNQUOTE().

proc sort data = %unquote(comment_&dataname) ;

  by subject aespid;

run;

Super User
Posts: 9,681

Re: what is the wrong with my macro code below?

OR Smiley Wink

proc sort data = comment_%unquote(&dataname) ;

  by subject aespid;

run;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 441 views
  • 2 likes
  • 3 in conversation