Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rename in Data Step

Status
Not open for further replies.

iren

Technical User
Mar 8, 2005
106
US
I am struggling trying to understand somebody’s code:

DATA OUT.&model._TOS; set ETG_2005.&model._IP_NEW (rename=(etg_amt_eqv=&model._IP) IN=A)

I am confused what renamed into what in this peace of code. First I assumed that =&model._IP was renamed into =&model._IP_new .
However it looks like etg_amt_eqv is also envolved…

Next I assumed that &model._ip was renamed into etg_amt_eqv before data step processed …however .&model._IP_NEW never existed before

So…my question is :what is going on in this code? Could you please help me with that?

Thank you!


 
Rename when used as a datset option refers to columns being renamed, not datasets. You were very nearly there..
Code:
DATA OUT.&model._TOS; 
  set ETG_2005.&model._IP_NEW(rename= etg_amt_eqv=&model._IP) IN=A)
  ...
Renames the variable etg_amt_eqv to &MODEL._IP which will obviously depend on the value of the macro variable &MODEL. If for example &MODEL = david your variable will be renamed to david_IP.

 
Chris, You said we rename columns, not datasets. However &model._IP looks like a dataset, doesn’t it?

I mean…if in the set statement ETG_2005 is a library, then &model._ip_new supposed to be a dataset?

If so…then &model._ip is a dataset either….. That what makes me very confused. How can we do equality statement between variable (field etg_amt_eqv) and dataset &model._ip? Could you please tell me where is a gap in my assumption?

Thank you very much!
 
My suggestion is to look up the RENAME dataset option in the SAS documentation listed above.

ETG_2005 is the library (libname)
&model._IP_NEW is referring to a dataset, note that &MODEL is a macro variable which will be replaced by its value at runtime.

RENAME=(var1 = Var2) is a dataset option to rename var1 to var2. There's no why or how, it's what the command does. Renaming a dataset requires the use of a PROC DATASETS step.
Dataset options (options in the brackets after a dataset name) tell SAS how to handle the data in the dataset named. If you think about it, logically it makes no sense to rename the dataset you are reading in to the datastep.

You want to check this section of the doco out

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top