06-22-2016 10:59 AM
Hi its me again.
I know the result its vodername. But I dont understand why I need no & in Line 2 (%Last=first) If i want reference to macro variable first then I need zo type $first, right?
06-22-2016 11:14 AM
Its quite simple.
What happens when this goes into the macro pre-processor. Well, it see's &last. which is a macro variable, so is de-references it to the text first. Then it looks at the statement again:
Which again is a macro variable, so it de-references it to be:
Which puts yourname in the log. Not sure where you get "vodername" from as thats not in the test data.
And just to confirm, you should put semi-colons after macro invocation otherwise it does not work, @Astounding, is quite correct. Also note, you should be putting "." after macro variables - whilst that is not required, it is good practice.
06-23-2016 08:25 AM
You need to use an & when you want to trigger the macro processor to convert your macro variable reference to the value that it represents.
You do not add an & when defining the value of a macro variable in a %LET statement because that is how the %LET statement works. The value before the equal sign is the name of the macro variable to create and the value after the equal is the value to assign to the macro variable.
Also if you did add an & it would trigger the resolution of the macro variable reference and instead of defining a macro variable named LAST you would be asking the %LET statement to define a macro variable whose name is contained in the existing macro variable named LAST. That is actually a valid statement and useful in many situations.
06-22-2016 11:28 AM
Yes a lot's been said about the semicolons and such so no need for me to do the same. But did you try yourself? I must assume you have SAS at your disposal so just suck it and see. It;s sometimes so easy to answer your own question. What did you find?
PS: The correct answer is:
ERROR: Open code statement recursion detected
06-23-2016 07:48 AM
There are a few issues that make it difficult to answer your question. First, do you agree that the semicolons are missing? Second, your question
Why do I not need & in %last=first? first is a value and not reference. I dont understand it.
refers to code that isn't in your initial example. So we must assume, again, what you actually mean. In the line
the ampersand is technically not needed. You will howewever assign the text 'first' to variable last and that may not be what you want. So it may be functionally needed. In that case you will assign the value of first to last.
My advice: be clear in what you want to achieve and what your expected results are versus your actual results. You just leave too much guesswork for those that so clearly want to help you out in what is certainly a problem at beginners level.
And use %PUT statements to check your results while experimenting. Simple but effective.
Need further help from the community? Please ask a new question.