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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

6 REPLIES 6
AndrewHowell
Moderator

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

Sasadomo
Calcite | Level 5

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

Reeza
Super User

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

Sasadomo
Calcite | Level 5

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

Reeza
Super User

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?


 

Kurt_Bremser
Super User

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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