BookmarkSubscribeRSS Feed
idziemianczyk
Obsidian | Level 7

In SAS9.4 there is a rule 1 byte = 1 character. 

 

Viya comes with Utf-8 and this rule no longer working. In utf-8 special characters can use 2,3,4 bytes, and some of the "standard" functions from SAS9.4 are not working in Viya.

 

K-functions are described here:

https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2018/1902-2018.pdf

and here:

https://documentation.sas.com/doc/en/vdmmlcdc/8.1/nlsref/p0ydidiqibf0vbn1jljj1cv9men9.htm

 

When we run the following code in SAS9.4 and SAS Viya 3.5 we'll see different results:

 

DATA test;
  name = 'éàè@&ùµ';
  len = LENGTH(name);
  sub = SUBSTR(name,5);
  klen = KLENGTH(name);  
  ksub = KSUBSTR(name,5);
RUN;  
proc print data=test; run;

The result in SAS9.4

 

idziemianczyk_0-1660721864069.png

The result in SAS Viya 3.5

idziemianczyk_1-1660721885696.png

 

As we can see, very popular functions like LENGTH or SUBSTR return the wrong results in Viya and we should use KLENGTH and KSUBSTR.

 

The question is:

Are there any other ways to migrate code from SAS9.4 to Viya3.5 without changing all non-K-Functions to K-Functions? 

At that moment it seems that backward compatibility doesn't work between SAS 9.4 code and SAS Viya 3.5.

 

1 REPLY 1
andreas_lds
Jade | Level 19

From the docs of length:

The LENGTH function returns a length in bytes. The KLENGTH function returns a length in a character-based unit.

So length returns the correct value in both environments, unfortunately many sas user (including myself) have ignored the fact, that the result depends on the encoding. Our 9.4 environment hast two SASApps, one for latin1 the other one for utf-8.

 

Are there any other ways to migrate code from SAS9.4 to Viya3.5 without changing all non-K-Functions to K-Functions?

Afaik there is no other way.

sas-innovate-2024.png

📢

ANNOUNCEMENT

The early bird rate has been extended! Register by March 18 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 225 views
  • 0 likes
  • 2 in conversation