So I figured it out. Sorry I was not keeping track of my log, so I don't have screenshots of the error as they popped in, but I have explained what error I had faced in the comments. I will directly paste the code here, to explain everything that I could not explain properly in my question, my most humble apologies for that. Somehow, I forgot to tell you that the first three variables are character, which I guess drastically affects the earlier solution that you gave. A big thanks to your sashelp.vcolumns suggestion, after which I could solve this. Request you to not micro-analyse my side of this, as all this is from someone who is fairly a fresher. data pg1.saket;
input from$ to$ Geo$ _2020_01 _2020_02 _2020_03 _2020_04 _2020_05;
datalines;
a b mah 3 4 5 6 7
c d ori 4 5 6 1 2
e f nep 5 4 3 1 66
g h kin 3 6 4 55 7
i j yup 44 5 3 22 55
;
run;
data vcolumns;
set sashelp.vcolumn;
where libname = "PG1" and memname = "&data_change." and type="num";
run;
/* duplicating this table from sashelp.vcolumn because it was not working somehow in proc sql alone*/
%let data_change = SAKET;
options validvarname = any;
/* because otherwise log was flagging an error, saying that it is expecting a name,
since 2020_07,and other such months begin by a number,
which is not allowed in sas variable naming convention*/
proc sql;
create table pg1.col_name as
select name as col_name
from work.vcolumns
quit;
data new_name;
set pg1.col_name;
new = substr(catx("%bquote('n)",catx ("%bquote(')","@",substr(col_name,2,7)),"|"),2,10);
run;
/* It took me a proper hour to get this. There was a problem right from putting
quotes inside double quotes, which was creating problem, so I had to search
and use %bquote and all that stunt. */
/* Basically, in the previous step, i converted _yyyy_mm in to the format of 'yyyy_mm'n */
proc print data= new_name;
run;
PROC SQL;
SELECT CATX("=", COL_NAME, new)
INTO :LIST_RENAME SEPARATED BY " "
FROM WORK.new_name;
QUIT;
%PUT &LIST_RENAME.;
PROC DATASETS LIB=pg1;
MODIFY saket;
RENAME &LIST_RENAME.;
RUN;
proc print data=pg1.saket;
run; Attaching images of result for your reference: Thank you for helping me out with this. Kindly urge you to copy this or something so that I could mark it as your answer, so that you could get your due credit. I feel you would have definitely explained this to me, perhaps more fluently and smoothly, had I explained the question a tad bit better in the first place. Thanks and Kind Regards ❤️
... View more