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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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