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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.