10-13-2016 10:18 PM
I am trying to subset my dataset based on months, and I want it to loop through the months and create a different dataset for each month.
This is my code:
%let start = 30JUN2014;
%do i=0 %to 10;
where DATE = '&mth'd;
It gives these error messages:
ERROR: Invalid date/time/datetime constant '&mth'd.
ERROR: Syntax error while parsing WHERE clause.
I am trying to generalise this, because when I use a hardcoded value (e.g. where DATE = '30JUN2014'd; ) it works.
I don't know why I can't just swap out the hardcoded value for &mth, giving that &mth shows as 30JUN2014.
I also tried just using where DATE = &mth; That doesn't work either.
10-14-2016 10:31 AM
Ohh, looks like I got it to work with
where DATE = "&mth"d;
double quotes, not single quotes.
**bleep** this is strange.
Not at all strange. The use of double quotes for macro variables to resolve is very well documented. For one thing it allows the use of literal text values containing possible macro invocations such as '%InData' or '&Sons' without the macro processor trying to handle such when you know they are not macro code or macro variables.
Need further help from the community? Please ask a new question.