06-18-2015 03:00 AM
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?
06-18-2015 03:10 PM
This is one of way
proc datasets library=work nolist;
rename var&indx="&stuffin"; ( which is Oldname = Newname)
format var&indx $8.;
/* call the macro that will create the labels */
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||')');
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.
06-19-2015 01:51 AM
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.