BookmarkSubscribeRSS Feed
R_A_G_
Calcite | Level 5
hi
How do I rename all my variables when they just differ in their suffix. and rename the file at the same time/

Thanks

%let num=4

DATA Q_Matrix_MIss;
MODIFY Q_Matrix;
RENAME skills1-skills&num=att1-att#
run;
end;
Ex:
5 REPLIES 5
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello R.A.G.,

I do not understand your syntax but renaming can be done with this simple macro:
[pre]%macro a(num=);
data r;
set i;
%do i=1 %to #
rename skills&i=att&i;
%end;
run;
%mend;
%a(num=2)
[/pre]
Sincerely,
SPR
ballardw
Super User
Instead of creating additional datasets using a data step I would suggest looking into PROC DATASETS which lets you modify datasets and properties of the variables within the dataset.
R_A_G_
Calcite | Level 5
Thank you and I'll look into the PROC as well.
Thanks again
polingjw
Quartz | Level 8
Although a proc datasets solution might be more efficient, the rename statement from your original code is valid. There are two problems with the code you posted. Since you are creating a new dataset instead of modifying an existing dataset in place, you need to use a set statement instead of a modify statement. Also, the end statement is not needed.
deleted_user
Not applicable
hello,

a more general macro solution which takes advantage of dictionary tables:

[pre]
data test;
array skills{10};
do i=1 to 5;
do j=1 to 10;
skills{j}=ranuni(10);
end;
output;
end;
run;

proc sql noprint;
select name into :all_var separated by ' ' from dictionary.columns
where libname=upcase('work') and memname=upcase('test') and name contains 'skills';
quit;

%macro change(new_suf);

%let i=1;

%do %until(%qscan(&all_var,%eval(&i)) eq %nrquote());
proc datasets library=work nolist;
modify test;
rename %qscan(&all_var,%eval(&i))=%sysfunc(cats(&new_suf,&i));
quit;
%let i=%eval(&i+1);
%end;


%mend change;

%change(att)
[/pre]

Marius

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 1101 views
  • 0 likes
  • 5 in conversation