How do I get SAS encoding option programmatically?
-
03-07-2019 - |
Question
How do I find out the SAS global encoding
option programmatically? I can run proc options
, and it will give me the answer, but I need to do it from code.
I am hoping for an answer on the lines of "look at the macro symbol &sysencoding", but this might be too much to hope for. I would prefer to avoid fragile things like writing to an external file and re-parsing.
Solution
You can use the GETOPTION function in Base SAS:
data _null_;
val=GETOPTION('encoding');
put val=;
run;
On my system this gives the log output
5 data _null_;
6 val=GETOPTION('encoding');
7 put val=;
8 run;
val=LATIN1
In SCL (SAS Component Language) you can use the OPTGETC and OPTGETN functions. See the manual for your specific version of the SAS System for further details.
OTHER TIPS
In SAS 9.2 &sysencoding
will give you the same thing as getoption('encoding')
though the case differs (it's described briefly here).
157 %put &sysencoding;
wlatin1
158
159 data _null_;
160 val=GETOPTION('encoding');
161 put val=;
162 run;
val=WLATIN1