DATA Step, Macro, Functions and more

SAS session encoding LATIN1 failing for unicode characters

New Contributor NVK
New Contributor
Posts: 3

SAS session encoding LATIN1 failing for unicode characters

My SAS session details are:-


I am reading encrypted customer names, decrypting them using a java code that has been implemented in the sas code using javaobj.

data outlib.X1 ( ENCODING =  'asciiany' );
set inlib.INP1 (ENCODING = 'asciiany' )   end=eof;
length decryptedvalue  $100;
declare javaobj jObj("<jarname>");
jObj.callstringmethod("<method>", FIRST_NAME , decryptedvalue);

The jObj.callstringmethod returns the decrypted first_name value in the string decryptedvalue. I do a proc export at the end of my SAS code and store all the decrypted names as csv files.

In the last run some of the names have special characters e.g. RÉAL.

This is causing SAS execution to fail with following error :-

ERROR: Transcoding failure at line 30 column 2.

ERROR: DATA STEP Component Object failure. Aborted during the EXECUTION phase.

Is there some way to make SAS session (LATIN1) accept these unicode characters? Can i set the encoding of the decryptedvalue variable? I dont want to run my entire SAS session in unicode using sas_u8. I only want to accept these characters Even reading these problematic values as blank is ok.

I have already tried following things :-

  1. Set inencoding= utf8 for the libname

  2. Make ENCODING = 'asciiany' for the input dataset.

Any inputs would be useful.

Thanks in advance!

Super User
Posts: 10,271

Re: SAS session encoding LATIN1 failing for unicode characters

encryption <> encoding (!)


Aside from that, you may have to change how SAS is being called, as UTF-8 requires DBCS-SAS:

Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
SAS Employee
Posts: 8

Re: SAS session encoding LATIN1 failing for unicode characters

The KPROPDATA function may help. You woudl need to pass in the string that is returned from Java. KPROPDATA would remove or convert any characters found in the string that are not supported by the SAS session encoding. Because you set the ENCOIDNG to ASCIIANY, you may need to specify the input and output encoding to the function. KPROPDATA is documented in the SAS National Language Support Reference Guide. 


As an alternative, if you own the Java code, you could call a method in Java that would convert to the Unicode escape representation. 

Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation