Create a CONSTANT or LITERAL in SAS

Reply
N/A
Posts: 1

Create a CONSTANT or LITERAL in SAS

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!

Super Contributor
Posts: 282

Re: Create a CONSTANT or LITERAL in SAS

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.

Respected Advisor
Posts: 3,799

Re: Create a CONSTANT or LITERAL in SAS

Regular Contributor
Posts: 227

Re: Create a CONSTANT or LITERAL in SAS

Posted in reply to data_null__

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

Ask a Question
Discussion stats
  • 3 replies
  • 222 views
  • 1 like
  • 4 in conversation