DATA Step, Macro, Functions and more

sas reference to a numeric variable name

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

sas reference to a numeric variable name

I was using the following lines:

 

proc transpose data =Weighted1 out =Weighted2
(rename = ( '1'n =ret_top '2'n=ret_bot) drop = _label_ );
...

where I wanted to rename variable named "1"  and named "2" in Weighted1 to "ret_tap" and "ret_bot" but SAS shows error for above line 2. How would Reference to such a variable?


Accepted Solutions
Solution
a month ago
Super User
Posts: 22,850

Re: sas reference to a numeric variable name

No, it's a SAS option.

 

This is what I recommend:

 

options validvarname=V7;

It means SAS will default to valid SAS names, by replacing spaces with _ and adding _ before variables with a 1 or 2. 

 


@Sasadomo wrote:

Thank you for your response, do I apply VALIDVARNAME=ANY option in the proc Transposes  command?


 

View solution in original post


All Replies
Moderator
Posts: 310

Re: sas reference to a numeric variable name

To help us to help you, are you able to supply (sample) data & the actual log?

Occasional Contributor
Posts: 14

Re: sas reference to a numeric variable name

Posted in reply to AndrewHowell

Thank you for you reply

 

I want Weighted2 as this: 20180422212400.png

 And in weighted1 "1" "2" are the variable name 

 

Attached is the log

Super User
Posts: 22,850

Re: sas reference to a numeric variable name

You don't show us what you're starting with, so it's still not clear. 

 

However, when SAS Transposes variables it automatically names them (usually col1, col2 etc), and I strongly suspect the names are not 1 or 2, so you first need to find the output names. I would do so by running the PROC TRANSPOSE, seeing the output data set and then renaming the variables accordingly. You probably want to run PROC CONTENTS to get the names. In general, I prefer to turn off the VALIDVARNAME=ANY option so I don't get names like '1'n in the first place. 

 

 

 

 


@Sasadomo wrote:

 

 

I want Weighted2 as this: 20180422212400.png

Occasional Contributor
Posts: 14

Re: sas reference to a numeric variable name

Thank you for your response, do I apply VALIDVARNAME=ANY option in the proc Transposes  command?

Solution
a month ago
Super User
Posts: 22,850

Re: sas reference to a numeric variable name

No, it's a SAS option.

 

This is what I recommend:

 

options validvarname=V7;

It means SAS will default to valid SAS names, by replacing spaces with _ and adding _ before variables with a 1 or 2. 

 


@Sasadomo wrote:

Thank you for your response, do I apply VALIDVARNAME=ANY option in the proc Transposes  command?


 

Super User
Posts: 9,574

Re: sas reference to a numeric variable name

Maxim 3: Know your data.

Run the proc transpose without the rename, inspect the variable names in weighted2, and then rewrite the rename accordingly.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 125 views
  • 0 likes
  • 4 in conversation