BookmarkSubscribeRSS Feed
Lindsey
Calcite | Level 5

Hi,

I have a list of column name in table temp --> var1, var2, var3, ..., var200.

I was able to rename var1 to studentID, var2 to studentGender. I would like to rename var3 to 2001-01, var4 to 2001-02, ... var13 to 2001-11, var14 to 2001-12, var15 to 2002-01, var16 to 2002-02, and ect. Is there a way to create those name in a do loop?

Many thanks!

3 REPLIES 3
ballardw
Super User

Please post questions in only one section of the forum unless recommended to a more appropriate location.

SukhwinderSingh
Calcite | Level 5

Hello;

This is one of way

%macro VarName(stuffin,indx);

    proc datasets library=work nolist;

   modify YOUR_DATASETNAME;

   rename var&indx="&stuffin"; ( which is Oldname = Newname)

   format var&indx $8.;

  run;

%mend VarName;

/* call the macro that will create the labels */

%macro loopin();

   %local i;

   attrib thename length=$8;

   %do i=3 %to &num_month;  (loop to maximum number of the column you have)

     thename=put(DateVariable,yymmd.);  /* help on format SAS(R) 9.3 Formats and Informats: Reference*/

  call execute('%VarName('|| thename||"," ||&i||')');

   %end;

%mend loopin;

We have used this for the labeling the column for the different year and month. I have modified little bit for you for the rename. If you have any problem let me.

Kurt_Bremser
Super User

Be advised that names like 2002-01 require the validvarname=any system option and the '2002-01'n naming construct, which will be a PITA to maintain further on.

Consider to use _2002_01 or the like.

As a programmer, I positively hate unnecessary typing.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1624 views
  • 0 likes
  • 4 in conversation