BookmarkSubscribeRSS Feed
whymath
Lapis Lazuli | Level 10

When using function foptname and filename contains Chinese character, it failed to return value. The prerequisites are:

1. Windows OS;

2. SAS 9.4 M8;

3. UTF-8 encoded SAS session;

And the active code page of my Windows OS is 936, which means simplified Chinese, a friend think this could be related.

 

Using foptname and finfo to get file attributes, with English file name:

 

filename _dummy_ "C:\Profiles\Work\temp\hello.sas";
data _null_;
 fid=fopen('_dummy_');
 if fid then do;
   do i=1 to foptnum(fid);
     foptname=foptname(fid,i);
     finfo=finfo(fid,foptname);
     put foptname ":" finfo;
   end;
   fid=fclose(fid);
 end;
run;

Log:

文件名 :C:\Profiles\Work\temp\hello.sas
RECFM :V
LRECL :32767
文件大小(字节) :634
上次修改时间 :2024年05月16日 10时06分17秒
创建时间 :2024年05月16日 10时06分17秒

The output is cool.

 

 

With Chinese file name:

filename _dummy_ "C:\Profiles\Work\temp\你好.sas";
data _null_;
 fid=fopen('_dummy_');
 if fid then do;
   do i=1 to foptnum(fid);
     foptname=foptname(fid,i);
     finfo=finfo(fid,foptname);
     put foptname ":" finfo;
   end;
   fid=fclose(fid);
 end;
run;

Log:

文件名 :C:\Profiles\Work\temp\你好.sas
RECFM :V
LRECL :32767
  :
  :
  :

Missing the last 3 output.

 

With Janpenese file name:

filename _dummy_ "C:\Profiles\Work\temp\こんにちは.sas";
data _null_;
 fid=fopen('_dummy_');
 if fid then do;
   do i=1 to foptnum(fid);
     foptname=foptname(fid,i);
     finfo=finfo(fid,foptname);
     put foptname ":" finfo;
   end;
   fid=fclose(fid);
 end;
run;

Log:

文件名 :C:\Profiles\Work\temp\こんにちは.sas
RECFM :V
LRECL :32767
  :
  :
  :

Missing the last 3 output.

 

Why I cann't get right output when filename contains MBCS? Is there a robust way to get file attributes regardless of the encoding or OS? Thanks in advance.

 

PS1: Under euc-cn(whichc means simplified Chinese) encoded SAS session, Windows OS, the problem just disappear.

PS2: Under utf-8 encoded SAS session, Linux OS, the problem just disappear.

3 REPLIES 3
SASKiwi
PROC Star

What's your SAS LOCALE settings for these tests? You can check using this code:

proc options option = locale;
run;
whymath
Lapis Lazuli | Level 10
Thank you, it is ZH_CN

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!

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
  • 3 replies
  • 238 views
  • 0 likes
  • 3 in conversation