thatnerd2
thatnerd2

Reputation: 544

Data step inside macro function

I have a series of similar files from which I need to create SAS datasets. I'd like to make a macro that, given the file name as a parameter, can output a data step. Is this theoretically possible?

I'm fairly new to SAS and I made this simple example:

%macro computeFormAndDomain(formName, domainName);
   data thing;
      input Name $;
      datalines;
      Bob 
      Jill
      ;
   run;
%mend;

%computeFormAndDomain("test", "test2");
proc print data=thing;
run;

However this gives back errors "ERROR: The macro COMPUTEFORMANDDOMAIN generated CARDS (data lines) for the DATA step, which could cause incorrect results. The DATA step and the macro will stop executing." What corrections need to be made, or is there a better way to achieve what I want?

Upvotes: 3

Views: 5945

Answers (1)

Joe
Joe

Reputation: 63424

You cannot use CARDS/DATALINES in a macro, by rule. You need to supply the information to the macro as an already constructed dataset (or, some other way). See for example this thread discussing the issue.

Upvotes: 3

Related Questions