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!
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.
For a constant like PI or E see the CONSTANT function.
SAS(R) 9.3 Functions and CALL Routines: Reference
For constants/literals see
SAS(R) 9.3 Language Reference: Concepts, Second Edition
For readonly symbol
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
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.