BookmarkSubscribeRSS Feed

Change Encoding using SAS Enterprise Guide/Windowing Environment/SAS Studio

Started ‎10-18-2019 by
Modified ‎10-20-2019 by
Views 28,533

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));

 

                          Encoding1.PNG

 

Now, to change the Encoding from WLATIN1 to UTF-8, We have to change in the configuration file.

See: Below Image (Expected Result)

 

                         Encoding2.PNG

 

To get this result follow the steps:

  1. 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.

 

  1. 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"

 

  1. 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"

 

  1. 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".

 

Encoding8.PNG

         Encoding7.PNG                        

               proc contents data=lib._all_; run;

 

            Encoding9.PNG                                 Encoding10.PNG

 

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;

 

           Encoding12.PNG                               Encoding10.PNG

 

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));

 

                                Encoding3.PNG

 

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));

 

                            Encoding4.PNG

 

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));

 

                             Encoding5.PNG

 

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));

 

Encoding6.PNG

 

References:

  1. http://support.sas.com/documentation/cdl/en/nlsref/63072/HTML/default/viewer.htm#p12mamjt5ccmshn1idw...
  2. http://support.sas.com/kb/15/597.html
  3. https://go.documentation.sas.com/?docsetId=movefile&docsetTarget=n06qan4j3ffr6fn11bs4q11r8r56.htm&do...
Comments

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?

Version history
Last update:
‎10-20-2019 11:59 PM
Updated by:
Contributors

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags