3

I have a global macro variable from another macro which looks like '01jan2014' when you print it in the log i.e. there are enforced quotemarks

I want to use this in a proc sql statement but I can't as it doesn't like the variable type.

How do I convert this into a date in the WHERE clause of my proc sql statement?

Joe
  • 62,789
  • 6
  • 49
  • 67
shecode
  • 1,716
  • 6
  • 32
  • 50

2 Answers2

7
%let yourdate = 01Feb2015;
%put &yourdate; /* resolve to 01Feb2015 */

proc sql;
select *
from have
where date ge "&yourdate."d;

or

%let yourdate2 = '01Feb2015'd;

proc sql;
select *
from have 
where date ge &yourdate2;

I think the first one is better since it won't contain ' in macro variable.

Lovnlust
  • 1,507
  • 3
  • 29
  • 53
  • by default it spits out the date with ' ' wrapped around with it without the date format. this is something in my program that can't be changed – shecode Feb 18 '15 at 20:21
5

To convert a date string in DDMONYYYY format, simple add a d to the end.

'01jan2014'd

will convert the string to a date.

In your case:

&var.d

will resolve to

'01jan2014'd

which will be interpreted as a date.

DomPazz
  • 12,415
  • 17
  • 23