DATA Step, Macro, Functions and more

The variable name   is not a valid SAS name

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 132
Accepted Solution

The variable name   is not a valid SAS name

[ Edited ]

I got this error when I'm importing a text data file to SAS. 

I know how to solve it by specifying the option 

options validvarname=any;

but I want to know why these variables' names don't fit with SAS variables rules  

 

ERROR: The name RELIF   is not a valid SAS name

ERROR: The name LVEF   is not a valid SAS name.

 

 


Accepted Solutions
Solution
‎04-12-2018 11:37 AM
Super User
Posts: 13,084

Re: The variable name   is not a valid SAS name


@mona4u wrote:

I got this error when I'm importing a text data file to SAS. 

I know how to solve it by specifying the option 

options validvarname=any;

but I want to know why these variables' names don't fit with SAS variables rules  

 

ERROR: The name RELIF   is not a valid SAS name

ERROR: The name LVEF   is not a valid SAS name.


When there does not appear to be a character but the error message seems to display an extra character then one possible culprit is a null character, ASCII value 255. Please see:

15   data junk;
16     x =123;
ERROR: The name x  is not a valid SAS name.
17      y=345;
ERROR: The name  y is not a valid SAS name.
18   run;

Notice in the second error there is an extra 'space' before the y and compared with the first error no space after y but is after x.

 

I typed the variable names, in Windows, alt-255 (hold the alt key and enter 255 using the numeric key pad) to add one character before or after y and x.

 

I think you might get a similar behavior if copying code from a non-text file format under some conditions.

We would have to see your code to have a shot at telling if this is the case. If you post code paste it into the code box opened on the forum with the {I} as it is possible that the main message window reformats such characters.

View solution in original post


All Replies
Respected Advisor
Posts: 2,661

Re: The variable name   is not a valid SAS name

Can we please see the relevant parts of the SASLOG so we can see what code was submitted and what the error messages were?

--
Paige Miller
Frequent Contributor
Posts: 132

Re: The variable name   is not a valid SAS name

Posted in reply to PaigeMiller

just edited it

Respected Advisor
Posts: 2,661

Re: The variable name   is not a valid SAS name

[ Edited ]

So from now on, in every post you make, we want to see code and SASLOGs posted in the {i} or running man window. No exceptions. Every single time you should do this. Otherwise, we are going to scream.

 

Something like this:

 

19 LVEF   $6
20 LVEFM $50
ERROR: The name LVEF   is not a valid SAS name.

It's not clear to me how this happened, but it appears there are special characters in the variable name that show as spaces. Note the extra spaces after LVEF (but not after LVEFM). Also see the extra spaces after LVEF in the ERROR message. 

 

You might want to try retyping the LVEF and RELIF lines making sure there are no special characters in the line.

 

--
Paige Miller
Solution
‎04-12-2018 11:37 AM
Super User
Posts: 13,084

Re: The variable name   is not a valid SAS name


@mona4u wrote:

I got this error when I'm importing a text data file to SAS. 

I know how to solve it by specifying the option 

options validvarname=any;

but I want to know why these variables' names don't fit with SAS variables rules  

 

ERROR: The name RELIF   is not a valid SAS name

ERROR: The name LVEF   is not a valid SAS name.


When there does not appear to be a character but the error message seems to display an extra character then one possible culprit is a null character, ASCII value 255. Please see:

15   data junk;
16     x =123;
ERROR: The name x  is not a valid SAS name.
17      y=345;
ERROR: The name  y is not a valid SAS name.
18   run;

Notice in the second error there is an extra 'space' before the y and compared with the first error no space after y but is after x.

 

I typed the variable names, in Windows, alt-255 (hold the alt key and enter 255 using the numeric key pad) to add one character before or after y and x.

 

I think you might get a similar behavior if copying code from a non-text file format under some conditions.

We would have to see your code to have a shot at telling if this is the case. If you post code paste it into the code box opened on the forum with the {I} as it is possible that the main message window reformats such characters.

Frequent Contributor
Posts: 132

Re: The variable name   is not a valid SAS name

It was minor things when I delete the variables and wrote them again it works. 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 188 views
  • 3 likes
  • 3 in conversation