0

I am trying to run a program with a prompt for a date in Enterprise Guide. I have the prompt configured, and it appears when I run the program. At the top of the program log I get the following lines that seem to show the macro values for the prompt are populating correctly:

7          %LET Processing_Month_end = 30Nov2015;
8          %LET Processing_Month = 01Nov2015;
9          %LET Processing_Month_label = November 2015;

My question is how to use these macro values as a date later in my program. If I try a simple data step:

data dates;
  refDate = &Processing_Month;
run;

I get the following error:

24         GOPTIONS ACCESSIBLE;
25         data dates;
26           refDate = &Processing_Month;
NOTE: Line generated by the macro variable "PROCESSING_MONTH".
26          01Nov2015
              _______
              22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN, 
              LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.  

27         run;

If I try to use input to format the value into a date:

data dates;
  refDate = input(&Processing_Month, date9.);
run;

I get a similar error:

24         GOPTIONS ACCESSIBLE;
25         data dates;
26           refDate = input(&Processing_Month, date9.);
NOTE: Line generated by the macro variable "PROCESSING_MONTH".
26         01Nov2015
             _______
             22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN, 
              LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.  

27         run;

If I try to wrap the macro value in a date literal:

data dates;
  refDate = '&Processing_Month'd;
run; 

Error:

24         GOPTIONS ACCESSIBLE;
25         data dates;
26           refDate = '&Processing_Month'd;
                       ____________________
                       77
ERROR: Invalid date/time/datetime constant '&Processing_Month'd.
ERROR 77-185: Invalid number conversion on '&Processing_Month'd.

27         run;

What syntax or function do I need to use with this prompt macro variable for it to function as a sas date?

Mr Beardsley
  • 3,743
  • 22
  • 28
  • 1
    See also, http://stackoverflow.com/questions/27946244/why-wont-my-macro-variable-resolve – Joe Nov 05 '15 at 17:15

1 Answers1

2

You're almost there. Date literal is the right answer, except you're missing one thing: '&mvar.' won't resolve, only "&mvar." will resolve. So switch to double quotes and trailing d, and you'll be right.

data dates;
  refdate = "&processing_month."d;
run;
Joe
  • 62,789
  • 6
  • 49
  • 67