An unexplained warning with a macro variable.

Reply
Occasional Contributor
Posts: 19

An unexplained warning with a macro variable.

[ Edited ]

Hello,

I don't understand why I had a warning when executing this piece of code:

%do i=1 %to 100;
%put %cmpres(&x%left(%sysevalf(&i.-1)));

 

WARNING: Apparent symbolic reference X not resolved.

Even though it gives the right result (X0=17)

 

I get the same warning result with

%put %cmpres(&x%eval(&i.-1));

 

 

 Thank you for your help

Frequent Contributor
Posts: 142

Re: An unexplained warning with a macro variable.

Posted in reply to Sam28041977

I think its because of missing '.' .use &x. if not resolved try to see other options if the macro variable "X" is declared outside of macro and you are trying to invoke that within a macro.

Super User
Super User
Posts: 9,599

Re: An unexplained warning with a macro variable.

Posted in reply to Sam28041977

You have written in your code: &x.  This x is a macro variable, denoted by the use of the ampersand.  The error is telling you that there is no macro variable called X in existence.  Thus it cannot de-reference the macro variable X and just displays the macro variable name X.  In the code you present there is no definition of a macro variable X, so why o you have &x?  To be honest, this:

%put %cmpres(&x%left(%sysevalf(&i.-1)));

 Looks a bit of a mess anyways, what are you trying to do/achieve?

 

Super User
Posts: 6,785

Re: An unexplained warning with a macro variable.

Posted in reply to Sam28041977

As @RW9 mentioned, there is no such thing as &x in this program.  That's where the message is coming from.  If you want to get x0 out of this, you could simplify with:

 

%put x%eval(&i.-1);

Occasional Contributor
Posts: 19

Re: An unexplained warning with a macro variable.

[ Edited ]
Posted in reply to Astounding

I have X0 (my initial value) and I want to calculate X1,...X100

it is why I need &X0, &X1, ...

X1 depend on X0 and X2 depend on X1, ...

As I mintionned in my email, the code works but I dont understand why given the warning.

What I provided you is just a small part of the code. 

the %put is just to reproduce the warning

 

Super User
Posts: 6,785

Re: An unexplained warning with a macro variable.

Posted in reply to Sam28041977

To get the value of &X0, try:

 

%put &&x%eval(&i.-1);

 

 

Occasional Contributor
Posts: 19

Re: An unexplained warning with a macro variable.

Posted in reply to Astounding

I already tested it even I didn't believe why it should work better.

The warning is still present 

Super User
Super User
Posts: 9,599

Re: An unexplained warning with a macro variable.

Posted in reply to Sam28041977

So your creating 100 macro variables, macro is not a replacement for Base SAS.  If your creating hundreds of data items, then a dataset is where to store that information.  If your using more than 2 or 3 macro variables, multiple de-references and %functions, then you should really re-think your problem as I can guarentee that there is a far simpler method of achieving what you want.

Occasional Contributor
Posts: 19

Re: An unexplained warning with a macro variable.

I am not creating 100 macro variables.

I am doing robust estimations by iterating until the difference in the estimate i and i-1 is close to 0.

As I get always this without reaching 100 iteration I fixed the max iteration to 100.

Only the final estimate interest me.

Super User
Super User
Posts: 9,599

Re: An unexplained warning with a macro variable.

Posted in reply to Sam28041977

Well, i am not a statistician, so can't guide as I would like, but checking the documentation, there appears to be quite a few examples in the documentation:

http://support.sas.com/documentation/cdl/en/procstat/67528/HTML/default/viewer.htm#procstat_univaria...

 

Occasional Contributor
Posts: 19

Re: An unexplained warning with a macro variable.

Thank you!

I am using a very specific calculus from an ISO guideline.

The problem is not about statistics.

I reformulate my question.

Why this code works (give the right result 17) but produce a warning?

%macro mac();
      %let i=1;
      %let x0=17;
      %put %cmpres(&x%eval(&i.-1));
%mend mac;
%mac();

 

Super User
Posts: 6,785

Re: An unexplained warning with a macro variable.

Posted in reply to Sam28041977

Probably lost in the confusion of so many messages ...

 

Your code refers to &X.  That means the macro variable X.  There is no macro variable X, hence the message.

 

Super User
Super User
Posts: 9,599

Re: An unexplained warning with a macro variable.

Posted in reply to Sam28041977

Well, its a real pain, and a very good example of why not use macro language for data processing.  However this example does work:

%macro mac();
      %let i=1;
      %let x0=17;
      %let x=x%eval(&i.-1);
     %put &&&x.;
%mend mac;
%mac();

You see how quickly that gets all messy, do it in a datastep, much nicer simpler code.

Super User
Super User
Posts: 8,127

Re: An unexplained warning with a macro variable.

[ Edited ]
Posted in reply to Sam28041977

@Sam28041977 wrote:

Thank you!

I am using a very specific calculus from an ISO guideline.

The problem is not about statistics.

I reformulate my question.

Why this code works (give the right result 17) but produce a warning?

%macro mac();
      %let i=1;
      %let x0=17;
      %put %cmpres(&x%eval(&i.-1));
%mend mac;
%mac();

 


Why are you calling the %CMPRES() macro? What do you want to remove?

To get the macro processor to re-evaluate a macro generated token use multiple &.  When it sees two & it converts them to one and sets flag that it needs to re-process the result to resolve more macro variable references.  Adding in the %EVAL() causes it to treat the string as multiple tokens instead of one.    

 

I find it is easier to either generate the new number into another macro variable. Or generate the macro variable name into another macro variable and use that to find the value.

 

Play with this example.

%let x1=One ;
%let x2=Two ;
%let one=Value of One ;
%let two=Value of Two ;

%let i=1 ;
%put &&x&i ;
%put &&&&&&x&i ;

%put &&x%eval(&i+1);
%put &&&&&&x%eval(&i+1) ;

%let j=%eval(&i+1) ;
%put &&x&j ;
%put &&&&&&x&j ;

%let name=x&i;
%put One=&name Three=&&&name Seven=&&&&&&&name  ;

%let name=x%eval(&i+1);
%put One=&name Three=&&&name Seven=&&&&&&&name  ;

 

Super User
Posts: 13,583

Re: An unexplained warning with a macro variable.

Posted in reply to Sam28041977

@Sam28041977 wrote:

I have X0 (my initial value) and I want to calculate X1,...X100

it is why I need &X0, &X1, ...

X1 depend on X0 and X2 depend on X1, ...

As I mintionned in my email, the code works but I dont understand why given the warning.

What I provided you is just a small part of the code. 

the %put is just to reproduce the warning

 


Show an actual example of what your are attempting with some values and the desired result.

I suspect that array processing might work an possibly no macro needed for that part.

Ask a Question
Discussion stats
  • 18 replies
  • 197 views
  • 1 like
  • 6 in conversation