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

Dear All,

I have a macro that checks many conditions such as these ones:

%IF %STR(&LEADER) NE %STR() %THEN %DO;

...

%IF %SYSFUNC(FILEEXIST(&PATH.\&SUPERVISOR.\&LEADER.)) %THEN %DO;

In the above, two of the arguments (SUPERVISOR and LEADER) can sometimes have hypens because they are names. When this happens, it yields the following error:

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric

       operand is required. The condition was: &LEADER NE

Is there any way around this or should I instruct users to remove hyphens when they call the macro?

Thank you in advance for your help and suggestions,

Daniel

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Use the %quote function

For example &path\%quote(&supervisor)\%quote(&leader)

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Use the %quote function

For example &path\%quote(&supervisor)\%quote(&leader)

--
Paige Miller
Astounding
PROC Star

An easy way for &LEADER would be:

%if %length(&leader) > 0 %then %do;

This could actually be abbreviated to:

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

Are you sure that &SUPERVISOR is actually causing a problem?  It looks like it should be OK.

PaigeMiller
Diamond | Level 26

A better way to check to see if a macro variable &leader is blank is:

%sysevalf(%superq(leader)=,boolean)

See http://support.sas.com/resources/papers/proceedings09/022-2009.pdf

This eliminates all possible problems caused by hyphens and other special characters

--
Paige Miller
Daniel
Obsidian | Level 7

Thank you both for your answers, everything works fine with the modifications you have proposed 🙂

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
  • 4 replies
  • 1756 views
  • 6 likes
  • 3 in conversation