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.
Open a track with SAS technical support. But since the return of FOPTNUM, FOPTNAME and FINFO is OS-dependent, this might be a fault in Windows itself.
What's your SAS LOCALE settings for these tests? You can check using this code:
proc options option = locale;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.