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
A. Changing the Encoding of the Session
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:
Go to the link: C:\Program Files\SASHome_foundation\SASFoundation\9.4\nls
There should be a configuration file sasv9.cfg in both "en" and "u8" folders.
There is a file sasv9.cfg on the location: C:\Program Files\SASHome_foundation\SASFoundation\9.4
Open it in notepad. Here you will find the config;
-config "C:\Program Files\SASHome_foundation\SASFoundation\9.4\nls\en\sasv9.cfg"
Make a small change in it. Just replace "en" with "u8" and Save.
-config "C:\Program Files\SASHome_foundation\SASFoundation\9.4\nls\u8\sasv9.cfg"
Open a new session of SAS Enterprise Guide and run the below code again.
proc options option=encoding;
run;
or
%PUT %SYSFUNC(getOption(ENCODING));
5. Now the Encoding of your system will change from WLATIN1 to UTF - 8.
B. Changing the Encoding of the Library
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.
C. Changing the Encoding of the SAS Dataset
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:
http://support.sas.com/documentation/cdl/en/nlsref/63072/HTML/default/viewer.htm#p12mamjt5ccmshn1idwaklce27jg.htm
http://support.sas.com/kb/15/597.html
https://go.documentation.sas.com/?docsetId=movefile&docsetTarget=n06qan4j3ffr6fn11bs4q11r8r56.htm&docsetVersion=9.4&locale=en
... View more