BookmarkSubscribeRSS Feed
whymath
Lapis Lazuli | Level 10

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?

 

3 REPLIES 3
yabwon
Onyx | Level 15

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:

yabwon_0-1737368493045.png

It allows me to create macrovariable with name ŻÓŁĆ and call it with symget()

Call with %put statement worked as well:

yabwon_3-1737368816181.png

 

Fun fact, when you preview sashelp.vmacro, when macrovariable name is not selected you can see:

yabwon_1-1737368648422.png

and when you select it:

yabwon_2-1737368689775.png

 

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


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
  • 273 views
  • 1 like
  • 3 in conversation