简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM