BookmarkSubscribeRSS Feed
yogita_patel
Calcite | Level 5

Hi ,

There is a variable DAI with values WEEK 2, WEEK 4, WEEK 8, WEEK 12, ..

If I transpose DAI variable then I get WEEK 2, WEEK 4,.. as variable

how can I change variable name from WEEK 2 to WEEK_2 ,...

As space is not accepted in variable name

But If i do before transpose like if DAI="WEEK 2" then dai_ "WEEK_2;

But it gives error when i transpose dai_ variable 

ERROR: The ID value "WEEK_2" occurs twice in the same BY group

can someone please give me solution?

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Please, when you are talking about data, show us a portion of the actual SAS data set, as SAS data step code (instructions). That would be very helpful. Do not attach Excel files, or provide the data in other formats.

 

Also, when you get errors in the log, SHOW US the log (all of it, every single line, every single character, for the PROC or DATA step that has the error)

--
Paige Miller
Reeza
Super User
Add this before your code:

option validvarname=v7;

Tom
Super User Tom
Super User

Without an example it is hard to tell what you are actually doing.

You seem to be asking two different questions.

To force PROC TRANSPOSE to generate valid variable names make sure you have set the option VALIDVARNAME=v7.  You might have accidentally had it set to VALIDVARNAME=any before.

 

If you have the same ID value in multiple times you need to decide how you want that transposed.

Perhaps you just need to add an extra BY variable so that you now longer have duplicate ID values for the same target observation.

Or perhaps you want eliminate the duplicate observation before calling PROC TRANSPOSE.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 506 views
  • 0 likes
  • 4 in conversation