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
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.
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?
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);
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
To get the value of &X0, try:
%put &&x%eval(&i.-1);
I already tested it even I didn't believe why it should work better.
The warning is still present
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.
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.
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:
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();
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.
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.
@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 ;
@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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: