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!

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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