BookmarkSubscribeRSS Feed
jaimepbs
Calcite | Level 5

Hi everyone,

I am trying to create a CONSTANT or LITERAL in SAS macro language, i mean a variable that can not be changed during the execution of the programme.

Macro Variables created with %let (global or local) can be changed... what i need is to define a variable that can not be changed (the classic example is the number pi=3,14151...). For instance, if I have constant1= 12345, if I writte in my programme %let constant1=789 the constant can not be changed.

In C language it is used the #define function.

Thank you!

3 REPLIES 3
Amir
PROC Star

Hi,

Have you considered defining a function to return the value you're interested in, would that be of help? E.g.:

%macro constant(const);

  %if &const=pi %then

    3.14

  ;

  %else

  %if &const=e %then

    2.71828

  ;

  %else

  %if &const=c %then

    299792458

  ;

%mend constant;

data _null_;

  put "pi=%constant(pi)";

  put "e =%constant(e)";

  put "c =%constant(c)";

run;

Regards,

Amir.

Ron_MacroMaven
Lapis Lazuli | Level 10

another option is an environment variable.

yes, they can be changed, but few people are aware of the syntax, nor how to access the symbol table

and so they are more or less, under the radar.

http://www.sascommunity.org/wiki/Using_Environment_Variables

here is the SAS statement syntax:

options set = Evar 'value';

Ron Fehd  evar maven

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 3 replies
  • 1967 views
  • 1 like
  • 4 in conversation