I've got this utility macro that I commonly use to add prefixes/suffixes to a list of terms. Recently I've also been using this to shorthand macro variable resolution, but despite the use of macro quoting, I'm getting a resolution warning of "Apparent symbolic reference N not resolved".
From my testing, the place where the warning appears is in the %QSYSFUNC(PRXCHANGE()) function. Below is the macro and a simple example illustrating the warning (I'm running SAS 9.4M3). I've included an example where if the prefix N had a value, it doesn't get resolved anyway. Almost like the macro compiler is doing a check for the macro variable but isn't actually trying to resolve it (not sure on why it would do this).
This nonissue has been bothering me for some time, appreciate any thoughts!
%macro qmodify_list(string, dlm_charlist=%str( ,), add_prefix=, add_suffix=, replace_dlm=) ;
%*----------------------------------------------------------------------------*;
%* STRING - list of delimited words *;
%* DLM_CHARLIST - delimiter for words in STRING *;
%* *;
%* ADD_PREFIX - characters to add before each word in STRING *;
%* ADD_SUFFIX - characters to add after each word in STRING *;
%* * NOTE: Above can use substitution regex characters, like $1 to add the *;
%* the matched string as a prefix or suffix *;
%* *;
%* REPLACE_DLM - characters to replace all consecutive delimiters *;
%* *;
%* Common applications: *;
%* *;
%* - Append prefix for a RENAME= option: *;
%* %modify_list(var1 var2 var3, add_prefix=%str($1=new_)) *;
%* -> returns: var1=new_var1 var2=new_var2 var3=new_var3 *;
%* *;
%* - Get a comma separated list of quoted values for an IN operator *;
%* %modify_list(PPN1 PPN2, add_prefix=%bquote(") *;
%* , add_suffix=%bquote(") *;
%* , replace_dlm=%str(,) *;
%* ) *;
%* -> returns: "PPN1","PPN2" *;
%* *;
%* Returned text is macro quoted, primarily used for input to other macros *;
%*----------------------------------------------------------------------------*;
%if %superq(string) = %then %do;
%put ERROR: [dev] List to modify (first parameter) was not provided.;
%put ERROR: [dev] Macro will ABORT CANCEL.;
%abort cancel;
%end;
%else %if %superq(add_prefix) = and %superq(add_suffix) = and %superq(replace_dlm) = %then %do;
%put WARNING: [dev] Neither ADD_PREFIX=, ADD_SUFFIX=, nor replace_dlm= parameters were given.;
%put WARNING: [dev] Supply at least one parameter to utilize this macro.;
%put WARNING: [dev] Original list will be returned.;
%superq(string);
%end;
%else %do;
%* BE SURE TO ESCAPE the charaters in the ADD_PREFIX or ADD_SUFFIX parameters with \
TO MASK PRX METACHARACTERS! E.g. \$ for $ or \\ for \;
%if %superq(replace_dlm) ne %then %do;
%let string = %qsysfunc(prxchange(s~[%superq(dlm_charlist)]+~%superq(replace_dlm)~,-1,%superq(string)));
%let dlm_charlist = %superq(replace_dlm);
%end;
%qsysfunc(prxchange(s!([^%superq(dlm_charlist)]+)!%superq(add_prefix)$1%superq(add_suffix)!,-1,%superq(string)))
%end;
%mend qmodify_list;
%macro modify_list(string, dlm_charlist=%str( ,), add_prefix=, add_suffix=, replace_dlm=);
%unquote(%qmodify_list(%superq(string)
, dlm_charlist=%superq(dlm_charlist)
, add_prefix=%superq(add_prefix)
, add_suffix=%superq(add_suffix)
, replace_dlm=%superq(replace_dlm)
)
)
%mend;
%let n1 = A;
%let n2 = B;
%put %qmodify_list(1 2, add_prefix=%nrstr(&n));
%put %modify_list(1 2, add_prefix=%nrstr(&n));
%let m = whoops;
%let m1 = C;
%let m2 = D;
%put %qmodify_list(1 2, add_prefix=%nrstr(&m));
%put %modify_list(1 2, add_prefix=%nrstr(&m));
98 %put %qmodify_list(1 2, add_prefix=%nrstr(&n));
WARNING: Apparent symbolic reference N not resolved.
&n1 &n2
99 %put %modify_list(1 2, add_prefix=%nrstr(&n));
WARNING: Apparent symbolic reference N not resolved.
A B
100
101 %let m = whoops;
102 %let m1 = C;
103 %let m2 = D;
104
105 %put %qmodify_list(1 2, add_prefix=%nrstr(&m));
&m1 &m2
106 %put %modify_list(1 2, add_prefix=%nrstr(&m));
C D
... View more