SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
NickA1
Calcite | Level 5

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;

21 REPLIES 21
NickA1
Calcite | Level 5

Looking to rename a variable and remove a column but I keep getting an error that says the variable has not been reference...here is my code

 

data YieldsRenamed (rename= (label_of_former_variable=cusip));

set Yieldstransposed;

run;

 

this wont rename it and where should I add in the remove argument?

 

PaigeMiller
Diamond | Level 26

Seems as if you are using the LABEL of a variable instead of the NAME of the variable.

 

(rename= (label_of_former_variable=cusip))

 

You might want to run PROC CONTENTS on this data set Yieldstransposed so you can see the actual name of the variable.

--
Paige Miller
NickA1
Calcite | Level 5

can you walk me through how to run proc contents?

Reeza
Super User
proc contents data=sashelp.class;run;

In the documentation for each procedure, there's an examples section that includes code that shows you how to use the procedure.

https://documentation.sas.com/?docsetId=proc&docsetVersion=9.4&docsetTarget=n1a5k5u51pvnlhn17j9v82nc...
ballardw
Super User

@NickA1 wrote:

Looking to rename a variable and remove a column but I keep getting an error that says the variable has not been reference...here is my code

 

data YieldsRenamed (rename= (label_of_former_variable=cusip));

set Yieldstransposed;

run;

 

this wont rename it and where should I add in the remove argument?

 


DROP on either input set or output set as dataset option or a DROP statement in the body of the data step code to "remove" a variable. One way:

data YieldsRenamed (rename= (name_of_variable_to_rename=cusip));
   set Yieldstransposed (drop=name_of_variable_to_drop);
run;

When to drop depends of when you want to use it. if you need it in the data step then either the drop statement or data set option on the output set. Otherwise it is a style choice.

NickA1
Calcite | Level 5

the variable is called "_label_" but this still didn't work when I tried to rename it

 

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

set Yieldstransposed;

run;

 

Astounding
PROC Star
Does your original data set already contain a variable named CUSIP? That would prevent renaming another variable to CUSIP.
NickA1
Calcite | Level 5

no but another data set has a variable named cusip. I want to merge these two variables. is it possible to do it without making them the same name?

KachiM
Rhodochrosite | Level 12
data YieldsRenamed (rename= (label_of_former_variable=cusip));

set Yieldstransposed;

run;

You are renaming in Output Data set. Do you want to RENAME label_of_former_variable in the Input Data set, Yieldstransposed ? 

NickA1
Calcite | Level 5
yes, exactly
KachiM
Rhodochrosite | Level 12
data YieldsRenamed;

set Yieldstransposed;
rename label_of_former_variable=cusip;

run;

Use rename this way in input data set.

Reeza
Super User
Did you check the YieldsREnamed data set for the renamed variable? Can you show a proc contents on that data set after you run the code above and include the log?
Tom
Super User Tom
Super User

@KachiM wrote:
data YieldsRenamed (rename= (label_of_former_variable=cusip));

set Yieldstransposed;

run;

You are renaming in Output Data set. Do you want to RENAME label_of_former_variable in the Input Data set, Yieldstransposed ? 


I really doubt if you have a variable named LABEL_OF_FORMER_VARIABLE.  You might have a variable named _LABEL_ that has a label of 'LABEL OF FORMER VARIABLE'.

NickA1
Calcite | Level 5
I already specified that this was indeed the case.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 3398 views
  • 0 likes
  • 7 in conversation