DATA Step, Macro, Functions and more

How to set a Macro that Renames Variable Names?

Reply
New Contributor
Posts: 3

How to set a Macro that Renames Variable Names?

So lets say if there are six excel files all containing similar variables names and their own observations, ie. in one excel file the variable name might be Payor Name, Name ID, Assigned Code, where the other excel might say Original Payor Name, Original ID, Proc Code and the third excel might say Original Payer Name, Original Name ID, Code. All have similar variable names that represents the same thing.

And now, I've successfully imported them into SAS and I want to rename the variable names so that they all have a standardized name, i.e. Payor Name, Payor ID, Code and because I am working with six excel files, I thought that it may be conveninet to write a macro that renames all the variable names, and this is where I am currently stuck on...

I'm new to SAS and understand the basics of macro and rename but combining them is my problem even though I feel like it is do-able. please help!

Super User
Super User
Posts: 7,060

Re: How to set a Macro that Renames Variable Names?

I doubt that a macro would add much value to this situation.  Unless it was an Excel macro that you gave out to the people supplying you with the data so that the files would be consistently formatted.

Just type the code into your editor and copy and paste it five more times and adjust for the differences.

data all;

set

   one (rename = ('Payor Name'n = payor  "Name ID"n = name "Assigned Code"n = code ))

   two (rename = ('Original Payor Name'n = payor  "Original ID"n = name "Proc Code"n = code )) 

   ........

New Contributor
Posts: 3

Re: How to set a Macro that Renames Variable Names?

Thanks Tom, I guess it is easier to do it that way.. than setting a macro. Thank you!

Super User
Posts: 19,822

Re: How to set a Macro that Renames Variable Names?

If the data was all in the same order then you could use PROC SQL Union all or Insert into and the names would be taken from the first file.

proc sql;

create table want as

select * from (

select * from table1

union all

select * from table2) a;

quit;

New Contributor
Posts: 3

Re: How to set a Macro that Renames Variable Names?

Thanks Reeza, I will give that idea a try. Thanks!

Ask a Question
Discussion stats
  • 4 replies
  • 594 views
  • 6 likes
  • 3 in conversation