3

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?

4
  • 1
    You can NOT use cards statement inside a macro. There are other ways to supply in-stream data to a macro. It would help to know more about what you are doing. I see you have a macro with two parameters but you don't use them so what's the story there? Commented Nov 4, 2015 at 18:37
  • @data_null_ Shouldn't you be posting the answer as an answer ;-) Commented Nov 4, 2015 at 18:40
  • Just to clarify something: this is not a macro function. This is a macro. A macro function doesn't exist in SAS; a function-style macro does, but does something totally different (returns a single value in open code). Commented Nov 4, 2015 at 19:46
  • @RobertPenridge I was thinking I would answer with something more useful once the OP supplied more info. Commented Nov 4, 2015 at 20:40

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.