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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 986 views
  • 1 like
  • 4 in conversation