Help using Base SAS procedures

Apsotrophy with ne

Accepted Solution Solved
Reply
Valued Guide
Posts: 617
Accepted Solution

Apsotrophy with ne

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?


Accepted Solutions
Solution
‎05-22-2018 09:36 AM
Valued Guide
Posts: 617

Re: Apsotrophy with ne

Posted in reply to DavidPhillips2

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

View solution in original post


All Replies
Solution
‎05-22-2018 09:36 AM
Valued Guide
Posts: 617

Re: Apsotrophy with ne

Posted in reply to DavidPhillips2

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

Super User
Super User
Posts: 9,599

Re: Apsotrophy with ne

Posted in reply to DavidPhillips2

Can you not just put quotes around it?

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

Another good reason not to use macro for data processing?

Valued Guide
Posts: 617

Re: Apsotrophy with ne

[ Edited ]

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.

Super User
Super User
Posts: 9,599

Re: Apsotrophy with ne

Posted in reply to DavidPhillips2

 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.

Super User
Posts: 10,770

Re: Apsotrophy with ne

Posted in reply to DavidPhillips2

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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