BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
zlerman
Fluorite | Level 6

I have imported an xlsx file in which columns have numerical names, e.g., 11003, 21003, 21103, and so on (more than 200 variables). The file imported correctly and I see the var names as 11003, 21003, 21103 in the output window and in the proc contents output. However, when I refer to my variables as 11003, 21003, 21103, etc., the SAS Studio does not recognize the variable names and produces an error message. I cannot run even a simple SAS program such as data a; set b; if 21103 eq 0; run; Variables with nonnumerical (character) names are recognized correctly, but if I try to print a mix of variables with nonnumerical and numerical names I get an error:

proc print data=coops.full2015; var ОКПО ОКВЭД 11103;
_____
22
200
ERROR 22-322: Syntax error, expecting one of the following: a name, ;, -, /, :, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.
ERROR 200-322: The symbol is not recognized and will be ignored.
 
Enclosing the numerical var name in quotation marks does not help: the same error is produced.
Please tell me how to access the variables with numerical names in my file.
 
Putting the numerical var name in quotes does not help:
proc print data=coops.full2015; var ОКПО ОКВЭД "11103"; run;
_______
22
200
 
ERROR 22-322: Syntax error, expecting one of the following: a name, ;, -, /, :, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.
 
ERROR 200-322: The symbol is not recognized and will be ignored.
 
Please help me to access the variables with numerical names in my file.
Thank you for your cooperation.
1 ACCEPTED SOLUTION

Accepted Solutions
Vince_SAS
Rhodochrosite | Level 12

Try something like this:

 

options validvarname=any validmemname=extend;

proc print data=coops.full2015; 
  var ОКПО ОКВЭД '11103'n;
run;

 

Note the letter n used with the numeric column name.

 

SAS® 9.4 and SAS® Viya® 3.4 Programming Documentation / SAS Language Reference: Concepts
Rules for SAS Variable Names

https://go.documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=lrcon&docsetTarget=p18...

 

Vince DelGobbo

SAS R&D

 

View solution in original post

4 REPLIES 4
Vince_SAS
Rhodochrosite | Level 12

Try something like this:

 

options validvarname=any validmemname=extend;

proc print data=coops.full2015; 
  var ОКПО ОКВЭД '11103'n;
run;

 

Note the letter n used with the numeric column name.

 

SAS® 9.4 and SAS® Viya® 3.4 Programming Documentation / SAS Language Reference: Concepts
Rules for SAS Variable Names

https://go.documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=lrcon&docsetTarget=p18...

 

Vince DelGobbo

SAS R&D

 

zlerman
Fluorite | Level 6

This works. Many, many thanks.

What is the precise function of the suffix "n"?

Is this topic (var name options, numerical var names in SAS Studio) covered anywhere in the instructions manual or the online help?

Best,

Zlerman

Vince_SAS
Rhodochrosite | Level 12

The letter "n" is used to distinguish between a quoted string and a name literal value.

 

The link that I posted earlier explains this.  This link is for the "SAS Name LIterals" section in the same Web page:

 

https://go.documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=lrcon&docsetTarget=p18...

 

Vince DelGobbo

SAS R&D

zlerman
Fluorite | Level 6

Thanks much. All is much clearer now, including the terminology ("name literals") and the system options that you have suggested.

Best.

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

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 14863 views
  • 4 likes
  • 2 in conversation