In a very unique situation, I see a guy's program and he use Chinese character as macro variable name, it supriesed me because I used to think the naming rules of macro variable is the same with dataset variable. But the code can really run without syntax error:
%let software=SAS;
%let 软件=SAS; *Chinese;
%let ソフトウェア=SAS; *Japenese;
%let 😀=SAS; *Emoji;
Run the code in unicode supported enviroment(&sysencoding is utf-8), you will see the top 3 statements will be execute without error.
However, when try to print the values of these variables, more suprising things comming:
%put &=software;
SOFTWARE=SAS
%put &=软件;
软件
%put &=ソフトウェア;
ソフトウェア
When printing values whose name are MBCS characters, names rather than values are printted.
Checking sashelp.vmacro, 软件
and ソフトウェア
are not found.
I ask this guy and know he use Chinese coded environment(&sysencoding is euc-cn), so I try the code in Chinese coded environment and result is different:
%let software=SAS;
%let 软件=SAS; *Chinese;
%let ソフトウェア=SAS; *Japenese;
%put &=software;
SOFTWARE=SAS
%put &=软件;
软件=SAS
%put &=ソフトウェア;
ソフトウェア=SAS
Macro variables whose name are MBCS characters behaves normal.
Checking sashelp.vmacro, 软件
and ソフトウェア
are found.
I am using SAS 9.4 M8 on Win11. After multiple attempts, I confirm that both two-byte and three-byte characters can be used as macro variable names.
Why MBCS characters can be macro variable name? How encoding impact macro variable store and parsing? Is it a bug?
I did a test in session with single byte encoding for Polish language:
%put &=sysencoding.;
%let software=SAS;
%let ŻÓŁĆ=sas; *Polish;
data test;
set sashelp.vmacro;
run;
data _null_;
x = symget('software');
put x=;
run;
data _null_;
x = symget('ŻÓŁĆ');
put x=;
run;
Log:
It allows me to create macrovariable with name ŻÓŁĆ and call it with symget()
Call with %put statement worked as well:
Fun fact, when you preview sashelp.vmacro, when macrovariable name is not selected you can see:
and when you select it:
Windows 10, SAS 9.4M8, single byte session.
You can count me in to the audience for the answers to your questions.
All the best
Bart
For me, this is a
BUG
Such things should never be allowed, but since the introduction of VALIDVARNAME=ANY idiocy runs rampant in the SAS world.
Kurt,
I agree with your opinion on this, it should not be allowed.
But it's not only a SAS case, in some languages it's done purposely: https://docs.julialang.org/en/v1/manual/variables/#man-variables
Bart
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.