BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TimMandell
Obsidian | Level 7

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.
*/
1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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;

 

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

View solution in original post

6 REPLIES 6
Astounding
PROC Star

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.

Kurt_Bremser
Super User

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.

TimMandell
Obsidian | Level 7

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.

 

Kurt_Bremser
Super User

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;
Quentin
Super User

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;

 

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
TimMandell
Obsidian | Level 7

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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 2481 views
  • 2 likes
  • 4 in conversation