BookmarkSubscribeRSS Feed
Gick
Pyrite | Level 9
/*Here my proposition of code*/

%macro remplacer_points(table_in, table_out);

data &table_out;
set &table_in;


array old_vars(*) _numeric_;
array new_vars(*) $ _temporary_;

do i = 1 to dim(old_vars);
/* Have Names variable */
var_name = vname(old_vars[i]);

/* Remplace (.) by (_) */
new_vars[i] = tranwrd(var_name, '.', '_');
end;


do i = 1 to dim(old_vars);
if not missing(new_vars[i]) then
rename old_vars[i]=new_vars[i];
end;

drop i var_name;
run;
%mend;


%remplacer_points(table_in=BDD_recod, table_out=BBB);
Gick
Pyrite | Level 9
/*Another code*/
%macro remplacer_points(table_in, table_out);

proc sql noprint;
select name into :varlist separated by ' '
from dictionary.columns
where libname = upcase(libname) and memname = upcase("&table_in");
quit;


data &table_out;
set &table_in;


%let num_vars = %sysfunc(countw(&varlist));
%do i = 1 %to &num_vars;
/* Obtenir le nom de la variable */
%let var_name = %scan(&varlist, &i);
%put &var_name.;


%let new_var_name = %sysfunc(tranwrd(&var_name, '.', '_'));
%put &new_var_name.;


rename &var_name = &new_var_name;
%end;
run;
%mend; Always the same

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

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 16 replies
  • 4712 views
  • 1 like
  • 8 in conversation