BookmarkSubscribeRSS Feed
ssitharath0420
Quartz | Level 8

Hello, 

 

I am getting this error when running the macro below:

 

A character operand was found in the %EVAL function or %IF condition where a
numeric operand is required. The condition was: &period=NUM

 

%macro section5(NUM);


/*Table 1 Period 1*/
%if &period=NUM %then %do;

data Tbl_1_row15;
set Tbl_1_row15;
Status='X1';
run;

data Tbl_1_Row15_P1000M;
set Tbl_1_Row15_P1000M;
Status='X2;
run;

data Tbl1_row16;
set Tbl1_row16;
Status=X3';
run;

data Tbl1_row16_P1000M;
set Tbl1_row16_P1000M;
Status='X4';
run;

data Tbl1_row17;
set Tbl1_row17;
Status='X5';
run;

data Tbl1_row17_P1000M;
set Tbl1_row17_P1000M;
Status='X6';
run;


data TBL_1_Export;
format Status $100.;
set Tbl_1_row15;
run;

proc append base = TBL_1_Export data = Tbl_1_Row15_P1000M force;
run;

proc append base = TBL_1_Export data = Tbl1_row16 force;
run;

proc append base = TBL_1_Export data = Tbl1_row16_P1000M force;
run;


proc append base = TBL_1_Export data = Tbl1_row17 force;
run;

proc append base = TBL_1_Export data = Tbl1_row17_P1000M force;
run;

OPTIONS VALIDVARNAME=ANY;
proc sql;
create table TBL_1_Export_Period._&num as
select distinct Status
,Total_members as "&pdstart_1.-&pdend_1"n
from TBL_1_Export;
quit;
%end;
%mend;
%section5(1)
%section5(2)
%section5(3)
%section5(4)

6 REPLIES 6
PaigeMiller
Diamond | Level 26

When code produces an error, we need to see the log (all of it, with nothing chopped out, in the order it appears in the log, for this macro call).

 

Use the command 

options mprint;

as the first line in your code, run it again, and show us the log. Please preserve the formatting of the log by copying it as text and pasting it into the window that appears when you click on the </> icon. DO NOT SKIP THIS STEP. I no longer try to help with logs where the formatting is not preserved as explained here.

--
Paige Miller
ballardw
Super User

Where is the value of the macro variable &period set?

If you expect to compare things to the macro parameter Num then you need to reference the parameter as &num .

Otherwise you are comparing to the text value "NUM".

 

One suspects that &period doesn't have any value at all. Which would resolve to.

 

%if  =Num %then %do.

Comparing the blank non-assigned value of &period to the text NUM.

ssitharath0420
Quartz | Level 8

Here is the code where I define the period.

 

%macro run_report;
%do period = 1 %to 4; * begin reporting loop;

* date calc adjustment;
%if &period = 1 %then %do;
%let adj=0;
%end;

%if &period = 2 %then %do;
%let adj=1;
%end;

%if &period = 3 %then %do;
%let adj=2;
%end;

%if &period = 4 %then %do;
%let adj=3;
%end;


* create date params;

data _null_;
format dt date9.;
dt = intnx('qtr', today(), - %eval(1 + &adj.), 'end');
call symput('dt',put(dt, date9.));
run;

data _null_;
format newstart date9.;
newstart = intnx('qtr', today(), - %eval(1 + &adj.), 'begin');
call symput('newstart',put(newstart, date9.));
run;

data _null_;
format tempd yymmdd10.;
tempd = intnx('qtr', today(), - %eval(2 + &adj.), 'begin');
pdstart=put(tempd,yymmdd10.)||' '||'00:00:00';
call symput('pdstart',pdstart);

run;

data _null_;
tempd = intnx('qtr', today(), - %eval(1 + &adj.), 'end');
pdend=put(tempd,yymmdd10.)||' '||'00:00:00';
call symput('pdend',pdend);
run;

/*pdstart_1 and pdend_1*/
data _null_;
format tempd mmddyys10.;
tempd = intnx('qtr', today(), - %eval(2 + &adj.), 'begin');
pdstart_1=put(tempd,mmddyys10.);
call symput('pdstart_1',pdstart_1);

run;

data _null_;
tempd = intnx('qtr', today(), - %eval(1 + &adj.), 'end');
pdend_1=put(tempd,mmddyys10.);
call symput('pdend_1',pdend_1);
run;

 


data _null_;
format priordt date9.;
priordt = intnx('qtr', today(), - %eval(2 + &adj.), 'end');
call symput('priordt',put(priordt, date9.));
run;

data _null_;
tempd = intnx('qtr', today(), - %eval(3 + &adj.), 'begin');
priorpdstart=put(tempd,yymmdd10.)||' '||'00:00:00';
call symput('priorpdstart',priorpdstart);
run;

data _null_;
tempd = intnx('qtr', today(), - %eval(2 + &adj.), 'end');
priorpdend=put(tempd,yymmdd10.)||' '||'00:00:00';
call symput('priorpdend',priorpdend);
run;

data _null_;
format tempd yymmdd10.;
tempd = intnx('qtr', today(), - %eval(4 + &adj.), 'begin');
naloxonepdstart=put(tempd,yymmdd10.)||' '||'00:00:00';
call symput('naloxonepdstart',naloxonepdstart);
run;

data _null_;
tempd = intnx('qtr', today(), - %eval(1 + &adj.), 'end');
format tempd yymmdd10.;
naloxonepdend=put(tempd,yymmdd10.)||' '||'00:00:00';
call symput('naloxonepdend',naloxonepdend);
run;

%put PERIOD: &period;

%put &dt;
%put &newstart;
%put &pdstart;
%put &pdend;
%put &pdstart_1;
%put &pdend_1;
%put &priordt;
%put &priorpdstart;
%put &priorpdend;
%put &naloxonepdstart;
%put &naloxonepdend;

 

Here is all the errors:

 

WARNING: Apparent symbolic reference PERIOD not resolved.
ERROR: A character operand was found in the %EVAL function or %IF condition where a
numeric operand is required. The condition was: &period=NUM
ERROR: The macro SECTION5 will stop executing.
WARNING: Apparent symbolic reference PERIOD not resolved.
ERROR: A character operand was found in the %EVAL function or %IF condition where a
numeric operand is required. The condition was: &period=NUM
ERROR: The macro SECTION5 will stop executing.
WARNING: Apparent symbolic reference PERIOD not resolved.
ERROR: A character operand was found in the %EVAL function or %IF condition where a
numeric operand is required. The condition was: &period=NUM
ERROR: The macro SECTION5 will stop executing.
WARNING: Apparent symbolic reference PERIOD not resolved.
ERROR: A character operand was found in the %EVAL function or %IF condition where a
numeric operand is required. The condition was: &period=NUM
ERROR: The macro SECTION5 will stop executing.

PaigeMiller
Diamond | Level 26

We need to see the entire LOG with nothing chopped out, not the code and parts of the log separated. Please follow the instructions given above to provide the LOG.

--
Paige Miller
ballardw
Super User

You really need to show the entire definition of the macro %Run_report. The snippet of code you show does not show where the %Section5 is called. So we still can't see where the value for period is in relation to that specific macro.

 

In this code:

data _null_;
format dt date9.;
dt = intnx('qtr', today(), - %eval(1 + &adj.), 'end');
call symput('dt',put(dt, date9.));
run;

The %eval is unneeded as long as &adj. resolves to something that looks numeric.

There is really no reason for multiple data _null_ steps if you do not have a data source such as Set statement.

For a lot of uses formatting values as character for date values just complicates later code unless the values are only used to create human readable text, titles or filenames. you have to use "&dt."D everywhere the actual date is used, such as in comparisons, filters, or date functions. Which may make code a bit ugly.

Astounding
PROC Star

Just to get you started in the right direction, this is surely the wrong comparison:

%if &period=NUM %then %do;

Since NUM is a macro parameter passed when calling %SECTION5, you must refer to it as:

%if &period=&NUM %then %do;

So this will get you started.  As always, fixing one problem may reveal another, later problem.  But start here.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2051 views
  • 0 likes
  • 4 in conversation