Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data step inside macro function

Tags:

sas

sas-macro

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?

like image 727
thatnerd2 Avatar asked Dec 11 '25 22:12

thatnerd2


1 Answers

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.

like image 196
Joe Avatar answered Dec 13 '25 20:12

Joe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!