BookmarkSubscribeRSS Feed
RWS
Calcite | Level 5 RWS
Calcite | Level 5

I need to rename some data step variables to the values of a set of macro variables.  The macro variables have new, different values each time the macro is invoked because a different parameter is passed to the macro with each call.  The macro is used to create a group of data sets, one for each of the parameters that are passed to the macro with an invocation of it.  Each of these datasets has a common set of dataset variables -- that is, they are common across all of the datasets created because they are created from a single, large dataset.  In each of the datasets, these dataset variables need to be given the names of the unique macro variable contents for that particular macro call.  The dataset variables need to be renamed because the datasets are merged together at the end of the program.

A simple rename type of statement like the following would be nice:

                                                          rename dataset variable = contents of macro variable.

However, I can't make this work.  Is there a way to accomplish this task?  I use version 9.4.

Thanks.

5 REPLIES 5
Quentin
Super User
Not quite following. Could you show a small bit of sample data, and how you would want to call the macro to rename the variables? Can you show what you have tried? Would a macro that allows you to rename a list of variables to add a prefix or suffix help?
The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
RWS
Calcite | Level 5 RWS
Calcite | Level 5

The other person who responded had a suggested solution that works.  Thanks anyway.

ballardw
Super User

There are several ways to do this depending on how persistent your macro variables are.

One way would be to rename them using proc datasets.

 

Proc datasets library=lib ;  /* put the name of the library where the data set you want to modify exists*/

   modify yourdatasetname;

      rename currentvar1 = &macrovar1

                   currentvar2 = &macrovar2

                   currentvar3 = &macrovar3

      ;    

run;

quit;

 

Another if the macro variables are persistent enough would be to have a rename in the data set options when actually combining the sets.

 

data big;

   set

       inputset1 (rename=(var1=&rename1_1 var2=&rename2_1)

       inputset2 (rename=(var1=&rename1_2 var2=&rename2_2)

       inputset3 (rename=(var1=&rename1_3 var2=&rename2_3)

   ;

run;

 

RWS
Calcite | Level 5 RWS
Calcite | Level 5

Your first suggested method for solving the problem works!  Thanks a lot.  It's a big help.

ballardw
Super User

Please mark an accepted solution so that other folks can see that the problem is solved. That helps other people find solutions to their problems.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1963 views
  • 0 likes
  • 3 in conversation