SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
clqa
Calcite | Level 5

why couldnt i have just done age=13 instead of age=&age? what is the purpose of macro variables?

Screen Shot 2018-09-21 at 9.48.12 AM.png

4 REPLIES 4
PaigeMiller
Diamond | Level 26

In this trivial example, the macro variable does nothing that you couldn't do better without the macro variable.

 

In other examples, macro variables allow code to be dynamic, and change as needed without the human programmer having to re-write or re-code large portions of text.

--
Paige Miller
data_null__
Jade | Level 19

@clqa wrote:

why couldnt i have just done age=13 instead of age=&age? what is the purpose of macro variables?

 

The purpose of macro variables is character substitution. 

bobpep212
Quartz | Level 8
Think about a bigger program where you have to reference age in lots of places. In this example, it references age in 2 spots. Using a macro variable instead means if you need to change the age, you only need to do it in one location. It also prevents you from accidentally not updating the age in one of the locations in your code.
Reeza
Super User

 

 

There is always more than one way to do something. 

What happens when you want to do it for each age in the data?

 

@clqa wrote:

why couldnt i have just done age=13 instead of age=&age? what is the purpose of macro variables?

Screen Shot 2018-09-21 at 9.48.12 AM.png


 

sas-innovate-white.png

Join us for our biggest event of the year!

Four days of inspiring keynotes, product reveals, hands-on learning opportunities, deep-dive demos, and peer-led breakouts. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1257 views
  • 2 likes
  • 5 in conversation