DATA Step, Macro, Functions and more

Macro resolving a value that includes a &

Accepted Solution Solved
Reply
Highlighted
Frequent Contributor
Posts: 101
Accepted Solution

Macro resolving a value that includes a &

HI all,

 

I have a macro that resolves a "&&byyear&i" into "E&M Nephrologist" and SAS keeps trying to resolve the & in E&M.  There's no error, just a warning in the log, but due to the fact that it's in code that takes a while to run, i have set it up to check &syserr and only continue when syserr=0.  But warnings are not zeros, so the code is stopping.

 

So i've updated the code that looked only for syserr=0 and changed it to syserr in (0 4), but it got me to thinking, is there a way to tell sas to ignore the & in the E&M, while at the same time, not ignore the &&byyear&i?

 

I need the &&byyear&i in double quotes or it won't resolve.

 

Any ideas?

 

 

 


Accepted Solutions
Solution
Friday
Trusted Advisor
Posts: 1,270

Re: Macro resolving a value that includes a &

"%superq(byyear&ii)"

View solution in original post


All Replies
Grand Advisor
Posts: 9,713

Re: Macro resolving a value that includes a &

It may help get a better answer by showing the code where you are using this.

Solution
Friday
Trusted Advisor
Posts: 1,270

Re: Macro resolving a value that includes a &

"%superq(byyear&ii)"

Esteemed Advisor
Esteemed Advisor
Posts: 6,693

Re: Macro resolving a value that includes a &

2 things.  Firstly why would a macro variable named by year, come out with that text?  Either naming is wrong or result is wrong.

Secondly, show the process.  A rule of thumb, if you see more than one & anywhere in code then there is 100% chance of refactoring the code to be much simpler and easier to understand.  

Trusted Advisor
Posts: 1,270

Re: Macro resolving a value that includes a &


RW9 wrote:

2 things.  Firstly why would a macro variable named by year, come out with that text?  Either naming is wrong or result is wrong.


Really, isn't this irrelevant to solving the problem?

 

Secondly, show the process. A rule of thumb, if you see more than one & anywhere in code then there is 100% chance of refactoring the code to be much simpler and easier to understand.

 I myself have sometimes fallen into the trap of telling people that there's only one right tool in SAS to solve the problem. But, what is the "right" way to solve a problem to you, and "simpler and easier to understand" to you, may not be the right tool for others and may be much more complicated and difficult to understand. I have no problem with code that contains &&, there are many situations where it has been useful to me.

Esteemed Advisor
Esteemed Advisor
Posts: 6,693

Re: Macro resolving a value that includes a &

"Really, isn't this irrelevant to solving the problem?"

Yes, it may be that the macro variable itself is not reolving correctly, or using the wrong data leading to the issue.  Byyear would indicate a variable should resolve to a year value, so why is the & appearing in such a way?

 

"byyear" - this in itself indicates by group processing.  If you feel having several && and convoluted methods to debug such code as against by group processing which is a fundamental concept of SAS, then good for you.

Frequent Contributor
Posts: 101

Re: Macro resolving a value that includes a &

Don't worry about what i name my macros.  It was supposed to resolve to E&M Nephrology and it did.  There is no error in my code.

 

The question i posted about was, how can i get sas to ignore the & in the E&M Nephrology value while not ignoring the & it has to resolve to get there.

 

 

Post a Question
Discussion Stats
  • 6 replies
  • 63 views
  • 0 likes
  • 4 in conversation