BookmarkSubscribeRSS Feed
GeethaMN
Obsidian | Level 7
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
1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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).

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 1230 views
  • 3 likes
  • 2 in conversation