1
votes

I would like to include the results of a macro function call in a data step. I can do this indirectly, by first assigning the macro function output to a macro variable, and then using that macro variable within my function, but this seems inelegant.

data dataset_employee;
input name $ dept $;
  datalines;
  John Sales
  Mary Acctng
;
data dataset_employee;
input name $ dept $;
  datalines;
  John Sales
  Mary Acctng
;

data dataset_manager;
input name $ dept $;
  datalines;
  Will Sales
  Sue Acctng
;

It seems like SAS doesn't realize that the macro call is complete and I'm switching to regular SAS code.

 /*this works*/
%let var = %DO_OVER(VALUES=employee, PHRASE=dataset_?) dataset_manager; 
data combined1;
  set &var dataset_manager;
run;

/*this fails*/
data combined;
  set %DO_OVER(VALUES=employee manager, PHRASE=dataset_?); 
  dataset_manager;
run;

/*this works*/
data combined;
  set dataset_manager %DO_OVER(VALUES=employee manager, PHRASE=dataset_?); 
  ;
run;

Can anyone help me understand what is going on here?

1
I don't see the code/definition for %DO_OVER in your post? Looks like it was accidentally deleted? Also the sentence between the 2 code blocks is currently truncated...Robert Penridge
%DO_OVER is a macro mentioned here www2.sas.com/proceedings/sugi31/040-31.pdf and can be downloaded here sascommunity.org/wiki/Tight_Looping_with_Macro_Arrays, but I suspect the same issue will come up with calling other macro functions.Lukas Halim

1 Answers

5
votes

It seems that the failing attempt is due to an extra ; at the end of the macro invocation. Try removing it.

A macro call doesn't require a semicolon. The first example works without a semicolon after the macro call (pay attention, you are using the dataset_manager dataset twice, in the %let and again in the set statement).

The third example would work even if you remove one of the two semicolons (one is required to end the set statement).