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.
You can set the session encoding by using the ENCODING= system option, the DBCS options, or the LOCALE= system option. Note: Values for the ENCODING= system option depend on the operating environment.
To run SAS in a session in UTF-8 encoding, you can do either of the following: at SAS invocation add the option, –encoding utf-8. add the system option to the SAS configuration file, ENCODING=UTF-8.
ENCODING= 'encoding-value'specifies the encoding to use for reading, writing, copying, or saving an external file. The value for ENCODING= indicates that the external file has a different encoding from the current session encoding.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With