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

When department has the value of Dean's Office.  The below errors 

 

%if &department ne %then %do;

 

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &department ne
ERROR: The macro DEPARTMENTWHERE will stop executing.

 

What can I use to allow the if statement to work?

1 ACCEPTED SOLUTION

Accepted Solutions
DavidPhillips2
Rhodochrosite | Level 12

%if %bquote(&department) ne %then %do;

View solution in original post

5 REPLIES 5
DavidPhillips2
Rhodochrosite | Level 12

%if %bquote(&department) ne %then %do;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Can you not just put quotes around it?

%if "&department." ne "" %then %do;

Another good reason not to use macro for data processing?

DavidPhillips2
Rhodochrosite | Level 12

What is the difference between '' and "" here? 

I think a the use of most functions around the parameter work work in this case.  I need the macro to print out a dynamic report.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

 Has to be double quotes for the macro variable to resolve.  Also, if you used single quotes it would be unbalanced.  Just think about what is resolved:

 

%if "Dean's Office" ne "" %then %do;

"I need the macro to print out a dynamic report." - the point is?  Many simple methods, categorise the data using numerics rather than text, use by group processing, combine categorisation and by group processing, generate code from datastep.  Reason I ask is that as soon as you fix the code to handle ', you can almost guarentee that the next run will include a ", or some other strange character.  Datasets can handle this fine, macro is really not good at data processing.

Ksharp
Super User

%if %length(&department)  %then %do;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1439 views
  • 2 likes
  • 3 in conversation