Reputation: 25
I have a query which uses date2
call symput('date2',strip(" ' "||put(intx('month',today(),-2,'B'),date9.))||" ' "));
%put &date2;
which basically gives the first day of 2 months prior to running date
and I Have another date which is '30jan2015'd
I want to write a where condition for date column such as
where datecolumn >= '30jan2015'd and datecolumn <= &date2;
When I tried this I am getting an error saying Expression using greater than or equal has components that are of different data types.
Could anyone help me on how I should change the query to make the where condition run, please?
Upvotes: 0
Views: 2356
Reputation: 27536
A SAS Date value is either a number, representing number of days from 01-JAN-1960
, or a date literal, which is a construct of form "<day>-<month>-<year>"D
.
Macro variables are resolved using the &
symbol in source code, not $
. Are you coming to SAS from a different coding language such as PHP
?
Because your ranges check is endpoint inclusive you can simplify the where
statement you are coding by using a BETWEEN
operator instead.
Example:
* place an unformatted date value (i.e. data value number) in macro variable;
data _null_;
call symput('date2',intx('month',today(),-2,'B'));
run;
* more code using a date literal and resolved macro variable;
data myDateRangeSubset;
set BigData;
where datecolumn between '30jan2015'd and &date2;
run;
If you are still getting log messages about different data types you will likely have to convert the datecolumn
from string to the appropriate SAS date value.
where input(datecolumn,date9.) between '30jan2015'd and &date2;
Upvotes: 4