Hello,
I copied over some code from SQL Server and I'm trying to create a where statement when the two-digit month of a date equals 10 (October). I'm getting an error back when I execute.
where XXXX
and a.month(timesent) = 10
_
22
76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN,
CONTAINS, EQ, EQT, GE, GET, GROUP, GT, GTT, HAVING, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.
ERROR 76-322: Syntax error, statement will be ignored.
The SQL alias applies to the variable, not the function. So to find the month of the variable TIMESENT from the dataset A (or dataset aliases as A) you would use.
month(a.timesent)
Now if your TIMESENT is really a datetime value and not a date value then you need also use the DATEPART() function to convert the number of seconds into number of days so that you can use the MONTH() function.
month(datepart(a.timesent))
Perhaps some example data and a little more of your code would be in order.
Function: MONTH
Purpose:
To extract the month of the year from a SAS date (1 = January, 2=February, etc.).
Syntax:
MONTH(date)
date is a SAS date value.
Examples
MONTH('16AUG2002'd)
8
Data Input;
input Acct_num Tran_Amt:dollar6. Tran_DT:mmddyy10. Item_ID:$3.;
format tran_Dt yymmdd10.;
datalines;
111 $100 6/1/2014 AAA
111 $200 8/2/2014 AAA
111 $500 6/4/2014 ABC
222 $300 8/3/2014 CCC
;
run;
proc sql;
select tran_amt
from input
where month(tran_dt) = 8;
quit;
yeilds
The SAS System 11:34 Friday, December 8, 2017 2
Tran_Amt
200
300
The SQL alias applies to the variable, not the function. So to find the month of the variable TIMESENT from the dataset A (or dataset aliases as A) you would use.
month(a.timesent)
Now if your TIMESENT is really a datetime value and not a date value then you need also use the DATEPART() function to convert the number of seconds into number of days so that you can use the MONTH() function.
month(datepart(a.timesent))
Duh! Why didn't I see month(a.time) vs a.month(time) ? Bang! Zoom!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.