3

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]);

Joe
  • 62,789
  • 6
  • 49
  • 67
renardeinside
  • 377
  • 1
  • 9
  • You don't actually have to do this in a macro, by the way; you can simply construct the hash arguments as strings in normal data step code. – Joe May 21 '14 at 14:00
  • In fact this is just for example, real program is more massive. I wanted to know the method of sending sas macro variables to text. But ofc thank u for attention.) – renardeinside May 22 '14 at 11:45

1 Answers1

3

Use double quotes and the macro variable will resolve.

declare hash merger (dataset:"data_&i.");
Laurent de Walick
  • 2,154
  • 14
  • 11