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?
%if %bquote(&department) ne %then %do;
%if %bquote(&department) ne %then %do;
Can you not just put quotes around it?
%if "&department." ne "" %then %do;
Another good reason not to use macro for data processing?
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.
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.
%if %length(&department) %then %do;
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.
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.
Ready to level-up your skills? Choose your own adventure.