BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pchilst
Calcite | Level 5

Hi all,

 

We've tried many solutions here but are encountering a problem still. I am opening an ODBC to a Postgres DB like this:

 

libname sql_read odbc dsn=OC64 schema=my_schema;

 

And it works, but the problem is the database is encoded with UTF-8, and some columns with unicode characters get translated over to SAS as non-unicode characters. For example, 

 gets turned into "=".

 

We've tested the exact same driver and ODBC in Python, and this problem doesn't exist, i.e. it is not mis-translating the data. So that suggests the problem is not with the driver or ODBC. 

 

Some other things we've tried are:

1. Ensuring the SAS session encoding is UTF-8. (Verifying this by doing a datalines with UTF-8 characters, which are correctly read)

2. Ensuring the column read into SAS has enough characters (it is character type and length 1024)

3. Trying to use the "correctencoding" argument, e.g. 

proc datasets library=perm nodetails nolist;
modify my_table/ correctencoding='utf8';
quit;

4. Trying to use the "outencoding" argument on the library, e.g.

libname perm "my_path" outencoding='UTF-8';

5. Trying to use a PROC SQL odbc passthrough instead of the libname statement (same result). 

 

Thank you for any help.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Hmm, usually encoding problems are solved by aligning encoding settings between applications. It looks like there are some character set differences between Postgres's UTF-8 and SAS's. I'd suggest raising a Tech Support track about this as they are in a better position to help.

View solution in original post

5 REPLIES 5
SASKiwi
PROC Star

What is your SAS session encoding?

proc options option = encoding ;
run;
pchilst
Calcite | Level 5

It's UTF-8 according to that proc. I am opening SAS by pointing it to the UTF8 config file:

 

"C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -CONFIG "C:\Program Files\SASHome\SASFoundation\9.4\nls\u8\sasv9.cfg"

 

Thanks.

SASKiwi
PROC Star

Hmm, usually encoding problems are solved by aligning encoding settings between applications. It looks like there are some character set differences between Postgres's UTF-8 and SAS's. I'd suggest raising a Tech Support track about this as they are in a better position to help.

pchilst
Calcite | Level 5
Sounds good, thanks for clarifying
waveson
Fluorite | Level 6

For anyone looking for solutions to this...
I just had the same problem - UTF8 sas session, UTF8 postgres db, but still getting ANSII characters.
I have solved it by adding connect settings in ODBC sources:

SET CLIENT_ENCODING TO 'UTF8'

waveson_2-1647607425075.png

hackathon24-white-horiz.png

Join the 2025 SAS Hackathon!

Calling all data scientists and open-source enthusiasts! Want to solve real problems that impact your company or the world? Register to hack by August 31st!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 3220 views
  • 1 like
  • 3 in conversation