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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4810 views
  • 1 like
  • 8 in conversation