1
%let stmDate = 05FEB2017;
%let stmDueDate = %sysfunc(intnx(day,"&stmDate"d,20),date9.);

data header;
    input  statement_date date7.
         statement_due_date date7.;
    format statement_date date7.
         statement_due_date date7.;
    datalines;
    &stmDate &stmDueDate
run;

How can I resolve the macro variable within the datalines?

1 Answer 1

1

SAS will not expand macro code in DATALINES. Note that there is no need in your example program. Just use the macro variables to generate the code needed to set your dataset variables.

data header;
  statement_date = "&stmDate"d;
  statement_due_date = "&stmDueDate"d ;
  format statement_date statement_due_date date9.;
run;

But if you did want to do this then take a look at PROC STREAM to convert the resolved lines into a file and then read from that file.

So create your macro variables.

%let stmDate = 05FEB2017;
%let stmDueDate = %sysfunc(intnx(day,"&stmDate"d,20),date9.);

Then use PROC STREAM to convert them into a data file. You could even have you macro function call.

filename text temp;

proc stream outfile=text; begin
&stmDate &stmDueDate
&stmDate %sysfunc(intnx(day,"&stmDate"d,20),date9.)
;;;;

Then read from the generated file. In general it will remove the line breaks so you might want to use @@ in your INPUT statement.

data header;
  infile text ;
  input statement_date statement_due_date @@ ;
  format _numeric_ date9.;
  informat _numeric_ date9.;
run;
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.