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;

 

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: 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;

 

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: 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-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
  • 6 replies
  • 2127 views
  • 2 likes
  • 4 in conversation