Search code examples
sassas-macro

sas string converting in code


I'm trying to use SAS 9.4 data hash obj. Some code here:

data joined;
    if 0 then set data1 data2;
    if _n_=1 then do;
        declare hash merger (dataset:'data2');
        merger.definekey('some_key');
        merger.definedata('col1','col2');
        merger.definedone();
    end;
    set data1;
    if merger.find(key:some_key)=0 then output;
run;

Now i want to make it macro played like:

%let list=2 3 4 5;
 data joined;
        if 0 then set data1 data_&i.;
        if _n_=1 then do;
            declare hash merger (dataset:'data_&i.');
            merger.definekey('some_key');
            merger.definedata('col1','col2');
            merger.definedone();
        end;
        set data1;
        if merger.find(key:some_key)=0 then output;
  run;

But as i see the problem is quotes around here:

dataset:'data_&i.'

How to convert this string for sas code? in python i can do smth like str(data[i]);


Solution

  • Use double quotes and the macro variable will resolve.

    declare hash merger (dataset:"data_&i.");