BookmarkSubscribeRSS Feed
Reeza
Super User
I believe that was in the other post not this one, which he may not have seen before I merged this one. Either way, I think you have the solution now, so this question can likely be closed.
Tom
Super User Tom
Super User

Show the lines of text from the SAS log. Make sure to use the Insert Code icon (looks like {i} on the menu bar) so that formatting is not lost.

 

There are two possible errors from the RENAME= option in your code.

1) The variable _LABEL_ does not exist on the input dataset.  If none of the variables being transformed had labels attached then PROC TRANSPOSE will NOT create the _LABEL_ variable.  You could eliminate the error by adding the variable into this step.

Of course then CUSIP is will not be very useful.

data YieldsRenamed2 (rename=(_label_=cusip));
  set Yieldstransposed;
  retain _label_ 'no label defined';
run;

2) The variable CUSIP is already on the dataset so you cannot rename some other variable to that name.

NickA1
Calcite | Level 5

 

49
50     data YieldsRenamed1 (rename=(_LABEL_=cusip));
51     set Yieldstransposed;
52     run;

NOTE: There were 138390 observations read from the data set WORK.YIELDSTRANSPOSED.
NOTE: The data set WORK.YIELDSRENAMED1 has 138390 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.11 seconds
      cpu time            0.07 seconds

here is the code from the log 

Tom
Super User Tom
Super User

No error there.

NickA1
Calcite | Level 5

but it  didn't rename my variable...

Tom
Super User Tom
Super User

Show the PROC CONTENTS of the NEW dataset.

Perhaps you are looking at the LABEL of the renamed variable instead of its NAME?  WHy not also change the label while you are at it?

 

I feel that frequently it is much clearer if you use the actual RENAME statement instead of the RENAME= dataset option.

data want;
  set have;
  rename _label_=CUSIP;
  label _label_='CUSIP generated from _LABEL_';
run;

 

 

Reeza
Super User

@NickA1 wrote:

I am trying to rename a column after transposing my data, but it wont let me... I keep getting a reference error...anyone know what I'm doing wrong? I ran proc contents and it looks like the variable name Is correct

 

data YieldsRenamed2 (rename=(_label_=cusip));

set Yieldstransposed;

run;


Please don't post the same question twice, I've merged them for now. 

 

What is likely happening is that you're seeing the variable label, not the variable name in your proc print, you've specified label. Renaming a variable does not change it's label, so you need to change it manually.

 

data YieldsRenamed2 (rename=(_label_=cusip));

set Yieldstransposed;

label _label_ = "CUSIP";

run;

There is also a likely easier fix, on the PROC TRANSPOSE output you can rename the variable right in that step. 

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 21 replies
  • 3909 views
  • 0 likes
  • 7 in conversation