BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SCS_78
Calcite | Level 5

Hello.

I used this macro many times in several programs and always works fine. Actually, this code already ran with no issues just a few days ago. However, I got this error and I don't know how to fix it. The macro tot_c is resolved correctly with value 34. Then I want to use this value in the loop where (%do j=1 %to &tot_c.) and sas returns the error bellow and stops. 

 

MPRINT(PREP_OS_STG): data _null_;
MPRINT(PREP_OS_STG): set DIM_CLUS_PSE;
MPRINT(PREP_OS_STG): call symputx("cluspselist"||trim(left(_n_)),CLUST_PSE_ATRIB);
MPRINT(PREP_OS_STG): call symput ("tot_c",_n_);
MPRINT(PREP_OS_STG): run;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
257:73 257:118
NOTE: There were 34 observations read from the data set WORK.DIM_CLUS_PSE.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds

MLOGIC(PREP_OS_STG): %PUT &tot_c.
SYMBOLGEN: Macro variable TOT_C resolves to 34
34
MLOGIC(PREP_OS_STG): Ending execution.
MPRINT(CALC_DIST_KM_STG1): ;
MLOGIC(CALC_DIST_KM_STG1): %LOCAL J N NEXT_CLUS_PSE
WARNING: Apparent symbolic reference TOT_C not resolved.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
&tot_c.
ERROR: The %TO value of the %DO J loop is invalid.
ERROR: The macro CALC_DIST_KM_STG1 will stop executing.
MLOGIC(CALC_DIST_KM_STG1): Ending execution.

1 ACCEPTED SOLUTION

Accepted Solutions
FrankPoppe
Quartz | Level 8
I guess you do not have a %GLOBAL statement for TOT_C, before calling macro PREP_OS_STG. The macro variable now is local to that macro, and unknown in the next macro.
Either add a %GLOBAL statement, or use CALL SYMPUTX ("tot_c" , _N_ , 'G' ) to put the macro variable in the Global table.

View solution in original post

3 REPLIES 3
FrankPoppe
Quartz | Level 8
I guess you do not have a %GLOBAL statement for TOT_C, before calling macro PREP_OS_STG. The macro variable now is local to that macro, and unknown in the next macro.
Either add a %GLOBAL statement, or use CALL SYMPUTX ("tot_c" , _N_ , 'G' ) to put the macro variable in the Global table.
PaigeMiller
Diamond | Level 26

It would help if you also showed us the code. And sorry to be picky, but it would also help if you used a larger font, the size of your text is difficult to read.

 

WARNING: Apparent symbolic reference TOT_C not resolved.

 

In macro PREP_OS_STG, you create the macro variable TOT_C and it has a value of 34. But, the default way SAS macros work, macro variable TOT_C is still undefined outside of the macro PREP_OS_STG, and so it does not have a value when the next macro CALC_DIST_KM_STG1 begins. I realize this does not explain how the code could have run in the past, but that's what I see, and as I said, showing us the code would help.

--
Paige Miller
Tom
Super User Tom
Super User

It is obvious how if COULD have worked in the past if you consider the complete rules for scoping of macro variables.

 

If you assign a value to a macro variable SAS will first use the macro variable of that name that it currently can see.  If no such macro variable exists it will make a new one in the current macro symbol table. Normally inside a macro that symbol table will be LOCAL to the macro currently running and so the macro variable created there will not exist after the macro ends execution.

 

So all you need to do to get your program to work is define the macro variable BEFORE calling the macro that you want to assign it a value.  

 

So add this line to the top of the program:

%let tot_c=not known yet ;

 

Or add this line to the top of the macro that assigning it a value:

%if not %symexist(tot_c) %then %global tot_c;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 598 views
  • 1 like
  • 4 in conversation