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

Hello folks.

I faced some strange thing today which I have never seen before.
After running a reference code that I have to use, I find out that some variables have numeric variable names (i.e. 1, 2, 3).

I want to make some changes to them but I have no idea how to refer them.

1.png

 

Task needs to be accomplished - Convert values in variables 1, 2, and 3 from numeric to char.

 

Thank you in advance.

 

Kind Regards

Artur

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Run a proc contents on the input data set and show that output please.


Or to fix the overall issue:

 

  • Add this line to your AUTOEXEC : options validvarname=v7;
  • Restart your SAS session
  • Reimport your data and SAS will provide usable names.

View solution in original post

8 REPLIES 8
maguiremq
SAS Super FREQ

That's a name literal, and it isn't a valid name. I'm assuming you have 

options validvarname = any;

specified somewhere.

 

You have to refer to it like this:

"1"n
options validvarname = any;
data want;
input '1'n;
datalines;
11
11
.
11
11
;
run;

proc means data = want;
	var '1'n;
run;

Probably a good idea to rename those to avoid the hassle of name literals.

Tom
Super User Tom
Super User

Someone must have changed your VALIDVARNAME option setting to ANY to allow it to create names like that.

To reference those non-standard names in SAS code you need to use name literals.  Add quotes and the letter N to the name.

proc freq;
  tables  '1'n  "2"N ;
run;
webart999ARM
Quartz | Level 8

Thank you for your response @maguiremq and @Tom , but it doesn't work that way.
I tried to perform three different actions with that variable with a numeric name, but had no success.

2.PNG1.png3.PNG

Reeza
Super User

Run a proc contents on the input data set and show that output please.


Or to fix the overall issue:

 

  • Add this line to your AUTOEXEC : options validvarname=v7;
  • Restart your SAS session
  • Reimport your data and SAS will provide usable names.
webart999ARM
Quartz | Level 8

Thank you @Reeza 

Added 'options validvarname=v7;' at the top of my program.

 

Now I have _1, _2, and _3 variables instead of 1, 2, and 3.

 

Appreciate all your responses guys.

 

Have a good rest of your day.

 

Regards

Artur

Kurt_Bremser
Super User

Most likely you have leading blanks also, which would cause the same effect:

options validvarname=any;

data have;
input " 1"n;
datalines;
1
;

data want;
set have;
one = "1"n;
run;

proc sql noprint;
select nliteral(name) into :names separated by " " from dictionary.columns
where libname = "WORK" and memname = "HAVE";
quit;

%put &names.;

The SQL will display the real names of the variables, which you can then use in further code to rename them.

webart999ARM
Quartz | Level 8

Interesting approach.

I will definitely try it.

Thank you 🙂

Kurt_Bremser
Super User

Since you import the data yourself, you can fix it there, which I also recommend. My approach is for situations where you receive a SAS dataset with such (IMO stupid) names and have to proceed from there.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 8 replies
  • 2749 views
  • 4 likes
  • 5 in conversation