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?
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?
To help us to help you, are you able to supply (sample) data & the actual log?
Thank you for you reply
I want Weighted2 as this:
And in weighted1 "1" "2" are the variable name
Attached is the log
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:
Thank you for your response, do I apply VALIDVARNAME=ANY option in the proc Transposes command?
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?
Maxim 3: Know your data.
Run the proc transpose without the rename, inspect the variable names in weighted2, and then rewrite the rename accordingly.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.