BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Dogo23
Quartz | Level 8

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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))

View solution in original post

3 REPLIES 3
HB
Barite | Level 11 HB
Barite | Level 11

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

 

Tom
Super User Tom
Super User

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))
HB
Barite | Level 11 HB
Barite | Level 11

Duh!  Why didn't I see month(a.time)  vs a.month(time) ?  Bang! Zoom!

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1860 views
  • 2 likes
  • 3 in conversation