3
votes

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?

2

2 Answers

6
votes
%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.

5
votes

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.