DATA Step, Macro, Functions and more

Understanding of macro quotes and ampersand

Reply
Super Contributor
Posts: 435

Understanding of macro quotes and ampersand

I've difficulties in understanding of using single quotes and double quotes in a macro. Also I would like to know usage of single ampersand and double ampersand as well. Ideally I wish to know the occasions where we tend to use double ampersand and single quotes and double quotes in a macro.

 

If someone can expalin it in simple terms I would be really grateful

 

Thanks in advance!

Super User
Posts: 5,426

Re: Understanding of macro quotes and ampersand

These are the most basic features of SAS macro. There are tons of papers, documentation and samples.

If you wish to develop macro programming skill, consider to take some training.

 

In short, everything between single quotes is unaffected by macro logic - no symbolic substitution will take place.

Between double quotes, substitution can take place.

 

Double ampersand can be used if you wish to nestle macro variable names in each other - in other words, store dynamically a macro variable name in another macro variable, and then wish to substitute to the original macro variable value.

Data never sleeps
Super User
Super User
Posts: 7,942

Re: Understanding of macro quotes and ampersand

LinusH has kindly provided an explanation.  I would like to add that in my opinion if you are finding you have more than one & or % in a line of code then there is almost always a better way of doing things.  Simply restructuring your data, coding differently, or using functions removes the need for all lof it.  Remember easy to read code is maintable by other people.

Ask a Question
Discussion stats
  • 2 replies
  • 201 views
  • 2 likes
  • 3 in conversation