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-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!

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.

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
  • 5 replies
  • 1037 views
  • 2 likes
  • 3 in conversation