How to debug this Macro definition error "Expecting a name"

Reply
Occasional Contributor
Posts: 15

How to debug this Macro definition error "Expecting a name"

options MPRINT MLOGIC MERROR SYMBOLGEN;

%macro srt(dsn=,s_dsn=,key=,byvar=,d_dsn=);
	proc sort data = &dsn out = &s_dsn &key dupout = &d_dsn;
	 by &byvar;
	run;
%mend;

%srt(dsn=sashelp.class,s_dsn = srt_cls,byvar = sex,key = nodupkey);

Hi All,

I have created a Standard macro for sorting procedure with all the possible macro keyword parameters.

The ERROR is at Dupout step is : Expecting a name.

 

At scenarios where need to store duplicate values  there won't be any error because i will be passing the value for that parameter.

 

But at some scenarios no need to store duplicate values. since it is keyword parameter no nee to pass value for  macro variable while calling a macro. here am getting error. it is as follows:

 

224  options MPRINT MLOGIC MERROR SYMBOLGEN;
225
226  %macro srt(dsn=,s_dsn=,key=,byvar=,d_dsn=);
227      proc sort data = &dsn out = &s_dsn &key dupout = &d_dsn;
228       by &byvar;
229      run;
230  %mend;
231
232  %srt(dsn=sashelp.class,s_dsn = srt_cls,byvar = sex,key = nodupkey);
MLOGIC(SRT):  Beginning execution.
MLOGIC(SRT):  Parameter DSN has value sashelp.class
MLOGIC(SRT):  Parameter S_DSN has value srt_cls
MLOGIC(SRT):  Parameter BYVAR has value sex
MLOGIC(SRT):  Parameter KEY has value nodupkey
MLOGIC(SRT):  Parameter D_DSN has value
SYMBOLGEN:  Macro variable DSN resolves to sashelp.class
SYMBOLGEN:  Macro variable S_DSN resolves to srt_cls
SYMBOLGEN:  Macro variable KEY resolves to nodupkey
SYMBOLGEN:  Macro variable D_DSN resolves to
NOTE 137-205: Line generated by the invoked macro "SRT".
1      proc sort data = &dsn out = &s_dsn &key dupout = &d_dsn;      by &byvar;     run;
                                                              -
                                                              22
ERROR 22-322: Expecting a name.

MPRINT(SRT):   proc sort data = sashelp.class out = srt_cls nodupkey dupout = ;
SYMBOLGEN:  Macro variable BYVAR resolves to sex
MPRINT(SRT):   by sex;
MPRINT(SRT):   run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.SRT_CLS may be incomplete.  When this step was stopped there were 0
         observations and 0 variables.
WARNING: Data set WORK.SRT_CLS was not replaced because this step was stopped.
WARNING: The data set WORK.NAME may be incomplete.  When this step was stopped there were 0
         observations and 0 variables.
WARNING: Data set WORK.NAME was not replaced because this step was stopped.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

MLOGIC(SRT):  Ending execution
SAAAS
Super User
Super User
Posts: 8,967

Re: How to debug this Macro definition error "Expecting a name"

Well, to answer your question;

options MPRINT MLOGIC MERROR SYMBOLGEN;

%macro srt(dsn=,s_dsn=,key=,byvar=,d_dsn=);
	proc sort data = &dsn out = &s_dsn &key 
          %if &d_dsn. ne  %then %do;
            dupout = &d_dsn
          %end
         ;
	 by &byvar;
	run;
%mend;

%srt(dsn=sashelp.class,s_dsn = srt_cls,byvar = sex,key = nodupkey);

However to add, why would you want to create a standard sort macro?  You are just obfuscating what is a simple base SAS procedure for no apparent reason.  Let me explain, all SAS programmers know how to write a proc sort step, now along comes the macro varient which wraps up some code and hides it behind a %srt call.  What does that mean, does it sort it ascending or descending, what about indexes, does it do anything else.  You have taken something simple and well known and obfuscated it.  Macro is not a replacement for Base SAS, and half the skill of creating an efficient standard macro library is knowing where to use macro and where not.

Also, please put the dot after macro variables, whilst not always necessary it is a good idea to always do it (and it will highlight in editor).

Ask a Question
Discussion stats
  • 1 reply
  • 112 views
  • 3 likes
  • 2 in conversation