BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BeeB
Calcite | Level 5

I am working with a dataset containing approximately 200 variables and almost all of them has a name like s_1_14, s_2_14, ... s_149_14, and obviously the variable names don't have the same length. 

 

I want to delete the "_14"-part of all the variable names, but I can't seem to figure out how to do it. I have tried the code from this post: Removing a suffix from a variable name , but since some of my variables are named s_144_14, it doesn't quite do the job. I really hope some of you how this is done other than renaming each variable manually 🙂

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

data have;
input s_1_14 s_2_14 s_149_14 s_144;
cards;
1 2 3 4
;

proc sql;
select catx('=',name,prxchange('s/\_14$//',-1,strip(name))) as renamex into: renam separated by ' ' from dictionary.columns where libname='WORK' and memname='HAVE' and prxmatch('m/\_14$/',strip(name));
quit;

data want;
set have;
rename &renam;
run;
Thanks,
Jag

View solution in original post

1 REPLY 1
Jagadishkatam
Amethyst | Level 16

data have;
input s_1_14 s_2_14 s_149_14 s_144;
cards;
1 2 3 4
;

proc sql;
select catx('=',name,prxchange('s/\_14$//',-1,strip(name))) as renamex into: renam separated by ' ' from dictionary.columns where libname='WORK' and memname='HAVE' and prxmatch('m/\_14$/',strip(name));
quit;

data want;
set have;
rename &renam;
run;
Thanks,
Jag

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

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 4324 views
  • 3 likes
  • 2 in conversation