DATA Step, Macro, Functions and more

Error in rename when variable is a value

Reply
Frequent Learner
Posts: 1

Error in rename when variable is a value

Hello, 

I am a novice SAS user and would much appreciate any advice regarding this error:

 
WARNING: The variable _1 in the DROP, KEEP, or RENAME list has never been
referenced.
 
The error shows up with the code:
 
proc transpose data=ewretdat out=ewretdat2
(rename = (_1=SELL _2=PORT2 _3=PORT3 _4=PORT4 _5=PORT5
_6=PORT6 _7=PORT7 _8=PORT8 _9=PORT9 _10=BUY));
by date;
id momr;
var ewret;
run;
 
The content of the momr column which I am transposing is a simple numerical integer (1 to 10). This issue is preventing me from referencing these new columns to pursue calculations.
 
Thanks in advance,
 
Nicolas
 
 
Respected Advisor
Posts: 3,889

Re: Error in rename when variable is a value

[ Edited ]

@nroux

The warning indicates that Proc Transpose doesn't create a variable _1. May be your variable momr never has a value of 1 in your source data.

 

Run your Proc Transpose statement first without the rename and check what variable names you actually get.

PROC Star
Posts: 7,363

Re: Error in rename when variable is a value

[ Edited ]

If you have to run the transpose on a number of datasets where not all momr values will be present each time, here is another way to assign the variable names you want:

 

data ewretdat;
  input momr ewret date date9.;
format date date9.; cards; 1 1 01apr2017 2 1 01apr2017 1 2 1may2017 2 2 01may2017 ; proc format; value momr 1=SELL 2=PORT2 3=PORT3 4=PORT4 5=PORT5 6=PORT6 7=PORT7 8=PORT8 9=PORT9 10=BUY ; run; proc transpose data=ewretdat out=ewretdat2; by date; id momr; var ewret; format momr momr.; run;

Art, CEO, AnalystFinder.com

 

PROC Star
Posts: 63

Re: Error in rename when variable is a value

@art297: There is a much easier way. Use the PREFIX= option in PROC TRANSPOSE:

proc transpose data=ewretdat out=ewretdat2 prefix=PORT;
  by date;
  id momr;
  var ewret;
run;

art297 wrote:

If you have to run the transpose on a number of datasets where not all momr values will be present each time, here is another way to assign the variable names you want:

 

data ewretdat;
  input momr ewret date date9.;
format date date9.; cards; 1 1 01apr2017 2 1 01apr2017 1 2 1may2017 2 2 01may2017 ; proc format; value momr 1=SELL 2=PORT2 3=PORT3 4=PORT4 5=PORT5 6=PORT6 7=PORT7 8=PORT8 9=PORT9 10=BUY ; run; proc transpose data=ewretdat out=ewretdat2; by date; id momr; var ewret; format momr momr.; run;

Art, CEO, AnalystFinder.com

 


 

Super User
Posts: 5,081

Re: Error in rename when variable is a value

While the variables won't always exist, you can get rid of the warning pretty easily.  Add this to your program:

 

options dkrocond=nowarn;

 

That won't add the missing variables, but it will get rid of the warning.

Ask a Question
Discussion stats
  • 4 replies
  • 129 views
  • 0 likes
  • 5 in conversation