BookmarkSubscribeRSS Feed
Sandy10
Calcite | Level 5

Hi

 

I am getting below error when executing below stmnt in a macro . Val is numeric and runstatus is character .

 

%if (val=0) AND (Runstatus = 'F' or RUNSTATUS='' ) %then 

 

 

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
val=1 and runstatus = "F" or ""

 

Kindly advise.Thanks

8 REPLIES 8
Kurt_Bremser
Super User

The text(!) val is never numeric; either you missed using the ampersand for macro variable &val, or you tried to access a data step variable, which is impossible from the macro preprocessor.

To clarify, post your complete code.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

%if construct is a macro function.  You cannot use datastep variables in the construct - macro is resolved before datastep compilation.

 

Post your code on what you are trying to do - we can't tell from tiny snippets.  First question would be why you are using a macro if construct to try to check datastep variables which will not work.

Sandy10
Calcite | Level 5
Hi. Yes am tryinh to access a datastep variable.

Data _null_
Set work.abc
if (val=0) AND (Runstatus = 'F' or RUNSTATUS='' ) %then



Both val and runstatus in abc table. Am doin in a loop inside a macro. Please advise how to reference both these varible in a macro. Thanks
Sandy10
Calcite | Level 5
Hi. Thanks. I wil try normal if else inside a data step . Is it possible to create a data step inside a datastel and uae filename statement?
Kurt_Bremser
Super User

There can only be one datastep active at any given time. Please describe what you want to accomplish, post example data (in a data step to easily recreate your data), and what your expected result should look like.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post examples, show test data in the form of a datastep, and what you want to achieve.  Its hard to keep guessing what you mean.  You can create code from one datastep in numerous ways:

data _null_;
  set have;
  if val=1 then call execute('data want;  file "abc.txt";...;run;');
run;

For example.

Sandy10
Calcite | Level 5
Hi. I want to try similar to wat you have posted. I will try and update here. Thanks for your reply.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 991 views
  • 0 likes
  • 3 in conversation