Hello,
I have two Macro variables that resolve to sentences when I attempt to compare them the evaluation method sees the first word in the resolved variable as another variable and provides and error as shown below. Thank you in advance for your response.
%do chg = 1 %to &m_ln;
/*response */
%if %sysevalf(%superq( &&asp&chg ) ne , boolean) %then %do;
%if "%NRBQUOTE(&&asp&chg)" ne "%NRBQUOTE(&&bsp&chg)" %then %do;
proc sql;
update dat.rvw_data set auditor = "&usr", Response="%NRBQUOTE(&&asp&chg)", audit_date="&srttm" where id= &&id&chg;
quit;
%end;
%end;
%end;
/*
where asp&chg and bsp&chg can resolve to values like
Clean Up your room
The room is clean
New Chore
Old Chore
example error
SYMBOLGEN: Macro variable ASP1 resolves to Clean Up your room
ERROR: Invalid symbolic variable name CLEAN.
*/
Looks to me like the problem is with %SUPERQ. You pass it the name of a macro variable without an & in front, unlike the other quoting functions which get passed a reference to a macro variable with the &.
Also, I don't think %NRBQUOTE is good for anything. I would suggest (untested):
%if %sysevalf(%superq(asp&chg) ne , boolean) %then %do;
%if %BQUOTE(&&asp&chg) ne %BQUOTE(&&bsp&chg) %then %do;
proc sql;
update dat.rvw_data set auditor = "&usr", Response="%BQUOTE(&&asp&chg)", audit_date="&srttm" where id= &&id&chg;
quit;
%end;
%end;
If these values are truly representative of your data, it is overkill to use double-quotes around %NRBQUOTE. Most likely the problem is stemming from the SQL code (not the %IF %THEN statement), since SQL is notoriously poor at parsing macro-quoted strings.
You can test the theory seeing if this change runs without error:
Response = "&&asp&chg"
The other %NRBQUOTEs are probably overkill but don't hurt anything.
And why are you doing this with a list of macro variables instead of a dataset?
Keep in mind that the macro processor is a code generator, not a data handler.
I have an input form using HTML/Javascript and initiated by stored process.
The variables contents to compare are the values obtained from the input form.
It seems very straight forward to compare the variables directly rather then moving the values into a dataset and making comparisons in that manner.
The next step after comparison is for inequalities replace the current value to the new value.
The fact that you had to come here seeking help should tell you that it is not straight forward at all.
That's because the macro processor is not the right engine for this at all. Once, again, it's a code generator, not meant to deal with data.
Both the data step and proc sql provide simple means for updating one dataset from the other. A check for inequality is not needed, as the update would replace a value with the same value anyway (in case of them being equal), causing no harm.
Getting a list of macro variables into a dataset OTOH IS straight forward:
%let asp1=The room is clean;
%let asp2=The room needs to be cleaned;
%let m_ln=2;
data data_upd;
length response $50;
do chg = 1 to &m_ln;
response = symget(cats('asp',chg));
output;
end;
run;
Looks to me like the problem is with %SUPERQ. You pass it the name of a macro variable without an & in front, unlike the other quoting functions which get passed a reference to a macro variable with the &.
Also, I don't think %NRBQUOTE is good for anything. I would suggest (untested):
%if %sysevalf(%superq(asp&chg) ne , boolean) %then %do;
%if %BQUOTE(&&asp&chg) ne %BQUOTE(&&bsp&chg) %then %do;
proc sql;
update dat.rvw_data set auditor = "&usr", Response="%BQUOTE(&&asp&chg)", audit_date="&srttm" where id= &&id&chg;
quit;
%end;
%end;
That was it... Was calling the %superq variable incorrectly (using && before first partial variable name).
and %bquote allows for the comparison.
Thank you
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.