In this Article, I am going to describe three ways to change the Encoding using SAS Enterprise Guide.
A. How to change the Encoding of the Session
B. How to change the Encoding of Library
C. How to change the Encoding of Dataset
When I run the below code in SAS Enterprise Guide, then the log show "ENCODING=WLATIN1". See: Below Image
proc options option=encoding;
run;
or
%PUT %SYSFUNC(getOption(ENCODING));
Now, to change the Encoding from WLATIN1 to UTF-8, We have to change in the configuration file.
See: Below Image (Expected Result)
To get this result follow the steps:
There should be a configuration file sasv9.cfg in both "en" and "u8" folders.
Open it in notepad. Here you will find the config;
-config "C:\Program Files\SASHome_foundation\SASFoundation\9.4\nls\en\sasv9.cfg"
-config "C:\Program Files\SASHome_foundation\SASFoundation\9.4\nls\u8\sasv9.cfg"
proc options option=encoding;
run;
or
%PUT %SYSFUNC(getOption(ENCODING));
5. Now the Encoding of your system will change from WLATIN1 to UTF - 8.
To change the encoding of entire library, I will explain the process considering an example. Suppose there are a lot of dataset in a library and someone want to change the particular encoding (like UTF-8, LATIN1, WLATIN1 etc.) of all the datasets, So, instead of changing encoding one by one of datasets change the encoding of the library. Now the encoding of all the datasets become same.
There are two datasets class_data_1 and class_data_2 with different encoding "wlatin1" and "utf-8" respectively. Both the datasets are in library "lib".
proc contents data=lib._all_; run;
Now run the below code to change the encoding of library. Notice that, there should be same path for inlib and lib library.
libname inlib cvp 'Path_1';
libname outlib 'Path_2' outencoding='UTF-8';
proc copy noclone in=inlib out=outlib;
run;
proc contents data=outlib._all_; run;
Thus, we can see that the encoding of all the data set has been changed into UTF-8.
Here, we will see the default encoding of dataset and change of encoding into "WLATIN1 Western (Windows)", "UTF-8 Unicode" and "LATIN1 Western (ISO)".
1. Default Encoding of Dataset:
To check the default encoding of base data, run the below code in SAS Enterprise Guide or Windowing Environment or SAS Studio.
%LET DSID=%SYSFUNC(open(sashelp.class,i));
%PUT %SYSFUNC(ATTRC(&DSID,ENCODING));
So, we can see that the default encoding of class dataset in sashelp library is "US-ASCII".
2. Encoding change from default:
When someone make any change in data or save in other library then the encoding become default according to your system configuration.
data work.class;
set sashelp.class;
run;
proc contents data=work.class;run;
or
%LET DSID=%SYSFUNC(open(work.class,i));
%PUT %SYSFUNC(ATTRC(&DSID,ENCODING));
3. Encoding change to UTF-8:
data work.class_2(encoding='utf-8');
set sashelp.class;
run;
proc contents data=work.class_2;run;
or
%LET DSID=%SYSFUNC(open(work.class_2,i));
%PUT %SYSFUNC(ATTRC(&DSID,ENCODING));
4. Encoding change to LATIN1:
data work.class_3(encoding='Latin1');
set sashelp.class;
run;
proc contents data=work.class_3;run;
or
%LET DSID=%SYSFUNC(open(work.class_3,i));
%PUT %SYSFUNC(ATTRC(&DSID,ENCODING));
References:
Thank you for an informative article. A question, is SAS dataset readable by SAS code or via EG/Explorer/program wise regardless of its encoding? For example, a SAS default setting is WLATIN1 and some datasets are in LATIN or UTF-8, is that still viewable?
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.