Search code examples
sassas-macro

Convert string with spaces to valid table name


I want to create a series of tables using SAS macro language, but the strings I am trying to pass through have spaces in them. Any ideas on what to add to make them valid table names?

%macro has_spaces(string);

proc sql;
create table &string. as 
select

*

from my_table
;
quit;
%mend;

%has_spaces(has 2 spaces);

Thanks.


Solution

  • Another option is translate:

    %macro has_spaces(string);
     proc sql;
      create table %sysfunc(translate(&string.,_,%str( ))) as 
        select *
        from my_table
      ;
     quit;
    %mend;