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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 3 replies
  • 996 views
  • 0 likes
  • 4 in conversation