Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get SAS encoding option programmatically?

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.

like image 228
Simon Nickerson Avatar asked Apr 29 '09 09:04

Simon Nickerson


People also ask

How do I set ENCODING in SAS?

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.

How can I change SAS session ENCODING to UTF-8?

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.

What does ENCODING mean in SAS?

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.


2 Answers

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.

like image 187
Martin Bøgelund Avatar answered Sep 20 '22 11:09

Martin Bøgelund


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
like image 31
cmjohns Avatar answered Sep 19 '22 11:09

cmjohns