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!
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.